Wow, such a major mistake, I had been overlooking. Thanks Chris Quinn and keep your glass always FULL :)
Raabi Anony
Posts
-
Record does not get updated -
Record does not get updatedThanks, Richard, for your attention and sorry for leaving out a change in the code, for the test purpose, as below:
Dim strUpdate As String = "UPDATE StaffName SET StaffName = 'Anonymous'" & "WHERE StaffID = 1005"
A record with the StaffID = 1005 exists. But the record doesn't get changed, as expected (by me :) ). What mistake I am doing. Please suggest. I have tried the following code, as well:
Private Sub StaffInfoAdapterUpdate() Dim ConxnString As String = "Data Source=Dar-e-Arqam\\SQLEXPRESS; Initial Catalog=StaffReport; Integrated Security=True" Dim Conxn As New SqlConnection(ConxnString) Dim cmd As SqlCommand = Conxn.CreateCommand() Dim StaffInfoDS As New DataSet() Dim StaffInfoAdapter As New SqlDataAdapter() Dim cmdText As String = "SELECT StaffID, StaffName, tblCampuses.CampusName, Designation, DOB, Gender, NIC, DateOfJoining FROM tblStaffInfo INNER JOIN tblCampuses ON tblStaffInfo.CampusID = tblCampuses.CampusID" Dim strUpdate As String = "UPDATE StaffName " & "SET StaffName = 'Anonymous' " & "WHERE StaffID = 1005" ' "SET StaffName = @StaffName " & "WHERE StaffID = @StaffID" Try Conxn.Open() cmd.CommandText = strUpdate cmd.ExecuteNonQuery() MsgBox("The record updated. Really?") Catch ex As Exception MsgBox("Error: " & ex.Message) End Try End Sub
The above code throws an error: "Invalide object name 'StaffName'. I am very disturbed for this problem. Please help.
-
Record does not get updatedThanks Homer, for your attention. I am reading the data in datagridView and modify it there only. Do I need to make changes for this scenario? Please suggest! Regards
-
Dynamic SQL generation is not supported against multiple base tablesThanks, Mycroft, for the link. I will try to follow it and may get back, if needed. Regards
-
Record does not get updatedHello geeks My struggle with Updating data seems never ending. My latest code is as below:
Private Sub StaffInfoAdapterUpdate(ByVal conxnString As String)
Dim cmdText As String
cmdText = "SELECT StaffID, StaffName, blCampuses.CampusName,
Designation, DOB, Gender, NIC, DateOfJoining
FROM tblStaffInfo
INNER JOIN tblCampuses
ON tblStaffInfo.CampusID = tblCampuses.CampusID"Using Conxn As SqlConnection = New SqlConnection(conxnString) Dim adapter As SqlDataAdapter = New SqlDataAdapter(cmdText, Conxn) Dim strUpdate As String = "UPDATE StaffName SET StaffName = @StaffName " & "WHERE StaffID = @StaffID" adapter.UpdateCommand = New SqlCommand(strUpdate, Conxn) adapter.UpdateCommand.Parameters.Add("@StaffName", SqlDbType.VarChar, 50, "StaffName") Dim parameter As SqlParameter = adapter.UpdateCommand.Parameters.Add("@StaffID", SqlDbType.Int) parameter.SourceColumn = "StaffID" parameter.SourceVersion = DataRowVersion.Original Dim StaffInfoTable As New DataTable Try adapter.Fill(StaffInfoTable) adapter.Update(StaffInfoTable) Catch ex As Exception MsgBox("Error: " & ex.Message) End Try End Using End Sub
When I modify the StaffName for testing, the code does not throw any error, but does not update the record either. Please note that StaffID is the Primary Key of tblStaffInfo Please help! I have a point to clarify in this respect: Do I have to include ALL the Fields in the strUpdate; which are included in cmdText string; even if most of the fields are least expected to be modified?
-
Dynamic SQL generation is not supported against multiple base tablesThank, RAH, for hinting towards a new direction for solution. I will try to implement the idea. Unfortunately, I am almost a novice in databases and therefore I have to struggle a lot in order to grasp the hints. I will appreciate, if you could emphasize a bit more on your point. Regards
-
Dynamic SQL generation is not supported against multiple base tablesThanks, Peter, for the attention. Let me try the stuff at the link, provided by you. I may get back, if further guidance is needed. Regards
-
Dynamic SQL generation is not supported against multiple base tablesHello everybody My following code seems very non-cooperative and issues the error: Dynamic SQL generation is not supported against multiple base tables
Dim conxnString As String = "Data Source=Raabi\\SQLEXPRESS; Initial Catalog=StaffReport; Integrated Security=True" Dim conxn As New SqlConnection(conxnString) Dim cmd As SqlCommand = conxn.CreateCommand() Dim StaffInfoDS As New DataSet() Dim StaffInfoAdapter As New SqlDataAdapter() Dim StaffInfoTbl As DataTable
Private Sub PopulateStaffInfoDGV()
Dim cmdText As String
cmdText = "SELECT StaffID, StaffName, tblCampuses.CampusName, Designation, DOB, Gender, NIC, DateOfJoining
FROM tblStaffInfo
INNER JOIN tblCampuses
ON tblStaffInfo.CampusID = tblCampuses.CampusID"Try cmd.CommandText = cmdText StaffInfoAdapter.SelectCommand = cmd conxn.Open() StaffInfoAdapter.Fill(StaffInfoDS, "StaffInfoTbl") StaffInfoDGV.DataSource = StaffInfoTbl conxn.Close() Catch ex As Exception MsgBox("Error: " & ex.Message) End Try
End Sub
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
Dim cmdbldr As New SqlCommandBuilder(StaffInfoAdapter)cmdbldr.GetUpdateCommand()
' Causes Error: Dynamic SQL generation is not supported against multiple base tables.
StaffInfoAdapter.Update(StaffInfoDS, "StaffInfoTbl")
End Sub
Any help is highly appreciated.
-
Aliasing Fieldnames and adding a calculation FieldThank you very much CHill60 and Dave for your help, especially very beautiful explanation by CHill60. Now, my problem got resolved. Wish you very good time and regards.
-
Aliasing Fieldnames and adding a calculation FieldHello everybody! I am facing two simple problems in the following code:
Dim cmdText As String cmdText = "SELECT tblStaffInfo.StaffName, tblCampuses.CampusName, LessonPlanning, LessonPreprn, Regularity, ((LessonPlanning + LessonPreprn + Regularity)/3 ) AS AvgScore FROM tblStaffInfo INNER JOIN tblCampuses ON tblStaffInfo.CampusID = tblCampuses.CampusID INNER JOIN tblStaffEvaluation ON tblStaffEvaluation.StaffID = tblStaffInfo.StaffID ORDER BY tblStaffInfo.StaffName"
(1)- The above Sql shows hatred for the division (/) sign (2)- How can use short alias for the long tables' name; like tblStaffInfo and tblCampuses etc. Please suggest!
-
Joining three tablesThank you very much, Richard Deeming, for the help. Have a very good day.
-
Joining three tablesHello everybody! I have three tables, namely t1, t2, t3
Dim cmdText As String
cmdText = "SELECT t1.StaffName, t2.CampusName
FROM t1
INNER JOIN t2
ON t1.CampusID = t2.CampusID
ORDER BY t1.StaffName"It is working fine. My problems starts when I want to include t3; such that;
t1.StaffID = t3.StaffID
I don't know; how to get it done. Please note that; StaffID is the Primary Key of t1 and the Secondary Key of t3. Would anyone help me, please!
-
WHERE clause of SELECT commandSorry everybody, I was committing a syntax error. It must be:
Dim cmdText As String = "SELECT * from tblStaffInfo tbl WHERE tbl.CampusName = '" & strCampusName & "'"
It is resolved.
-
WHERE clause of SELECT commandHello everybody! A newer problem on a newer day :) This time, I am facing a very basic issue in the following code:
Private Function GetDataSource(strCampusName) As DataTable Dim cmdText As String = "SELECT \* from tblStaffInfo tbl WHERE tbl.CampusName = " + strCampusName Dim conxnString As String = "Data Source=Raabi\\SQLEXPRESS; Initial Catalog=StaffReport; Integrated Security=True" Dim DGVadapter As New SqlDataAdapter() Dim ds As New DataSet() Dim conxn As New SqlConnection(conxnString) Dim cmd As SqlCommand = conxn.CreateCommand() Try cmd.CommandText = cmdText DGVadapter.SelectCommand = cmd conxn.Open() DGVadapter.Fill(ds) Return ds.Tables(0) conxn.Close() Catch ex As Exception MsgBox("Error: " & ex.Message) End Try End Function
Error: Invalid column name 'whatever' Even if I use, for example;
Dim cmdText As String = "SELECT * from tblStaffInfo tbl WHERE tbl.CampusName = CityCampus"
I receive the same error. Any help, please!
-
DGV with multiple TablesSorry for another show up with hope. I am still stuck with the
Dim conxnString As String = My.MySettings.sqlConnectionString
Or
Dim conxnString As String = My.Settings.sqlConnectionString
VisualStudio 2015 says "sqlConnectionString is not a member of MySettings" Do I need to Import some Library, other than System.Data.SqlClient ? My whole code is as below:
Private Function cboCampuses_SelectedValueChanged(sender As Object, e As EventArgs) Handles cboCampuses.SelectedValueChanged
Dim selectedValue As String
selectedValue = cboCampuses.SelectedValue
Me.StaffEvaluationDGV.DataSource = GetDataSource(selectedValue)
End FunctionPrivate Function GetDataSource(selectedValue) As DataTable Dim sqlSelect As String = "SELECT \* FROM tblEvaln " & "WHERE CampusName = " & selectedValue Dim SqlConnection As SqlConnection Dim conxnString As String = My.MySettings.sqlConnectionString Try Dim table = New DataTable() Using con = New System.Data.SqlClient.SqlConnection(conxnString) con.Open() Using da = New System.Data.SqlClient.SqlDataAdapter(sqlSelect, con) da.Fill(table) Return table End Using End Using Catch ex As Exception ' Error message here End Try End Function
Would anybody help me please!
-
DGV with multiple TablesThanks a lot for the responses and sorry for the late acknowledgment. Let me try your suggestions and may get back to you geeks for further help, if necessary. Actually, I am using Microsoft SQL Server. I have fair knowledge of programming in VB.NET, in general, but not in databases. Would anyone suggest the necessary correction, in view of using MS SQL Server, because this piece of code can serve my purpose, at the moment. Have a good time.
-
DGV with multiple TablesHi everybody I had been trying to code a DatagridView with multiple tables, without much success, until I found the following code; which seems fulfilling my aspirations:
Private Function GetDataSource() As DataTable
Const sqlSelect As String = "SELECT a.Col1 AS aCol1, a.Col2 AS aCol2, b.Col1 AS bCol1, b.Col2 AS bCol2 " & _
"FROM dbo.TableA AS a
INNER JOIN dbo.TableB AS b ON a.IdCol = b.aIdCol " & _
"ORDER BY aCol1 ASC, bCol1 ASC"
Try
Dim table = New DataTable()
Using con = New MySqlConnection(My.Settings.MySqlConnectionString)
con.Open()
Using da = New MySqlDataAdapter(sqlSelect, con)
da.Fill(table)
Return table
End Using
End Using
Catch ex As Exception
' log message instead '
Throw ' don't use throw new Exception or throw ex '
End Try
End Function
me.DGV1.DataSource = GetDataSource()But, unfortunately, it gives a couple of the following errors: MySqlConnection is not defined MySqlDataAdapter is not defined Looking forward for some explanation and remedy for these errors. Please help!
-
SelectedValue of Combox Not saved in the tableHi In my data entry form, all the fields are bound to a tblStaff table through BindingSource (_staffInfoB_S). One of these controls is a cboGender ComboBox. I am manually populating the cboGender with only two items -- "Male" and "Female" and trying the SelectedValue to be saved in the underlying table, using the following code:
cboGender.Items.Add("Male")
cboGender.Items.Add("Female")
Dim bndg As New System.Windows.Forms.Binding _
("SelectedValue", StaffInfoBindingSource, "Gender", True)
cboGender.DataBindings.Add(bndg)But, it doesn't save the SelectedValue in the underlying table. Looking for a suggestion, please!
-
Adding Items to data-bound Combo BoxHello! In my data entry form, all the fields are bound to a tblStaff table through BindingSource (staffInfoBS). One of these controls is a cboGender ComboBox. I want to manually populate the cboGender with only two items -- "Male" and "Female" and the SelectedValue be saved in the underlying table. If I try to use something like Items.Insert, I receive error: Items collection cannot be modified when the DataSource property is set. How can get it done. Please suggest.
-
Saving data with data-bound Form ControlsThanks for a response, at least. I am using MS SQL Server 2015 Express edition and working in VisualBasic.NET. Not a single project is functioning to Insert or Update any record, whether in DataGridView or in detailed format. I M suffering and seek help desperately. Regards