The problem I am having is this:
I have 2 save buttons on my form. 1 is part of the bindingnavigator and the other is just a simple button(btnSave). btnSave is used to save changes/new records in the datagridview back to the SQL table. The binding navigator save button is used to save Invoice records to a seperate SQL table. When a new invoice is entered, the bindingnavigator save button is clicked, and on this click event, a stored procedure fires and grabs some data from Access that matches the Shipping Report number entered in the data entry part of the app. 1 record is found for each new invoice entered and is then saved to a table called t_groupdata. This record is also displayed in the DGV.
The user can then make any changes to this record in the DGV or add an additional record if needed. Once this is done, they click btnSave to save those changes back to t_groupdata. I am getting multiple records if I save the changes in the DGV and then come back later and make changes to the original Data Entry and use the binding navigator save button. I get double records with each click of the binding navigator save button. Here is my code
Any explanation or solution to this would be greatly appreciated. I am running out of time and in quite a pickle!
I have 2 save buttons on my form. 1 is part of the bindingnavigator and the other is just a simple button(btnSave). btnSave is used to save changes/new records in the datagridview back to the SQL table. The binding navigator save button is used to save Invoice records to a seperate SQL table. When a new invoice is entered, the bindingnavigator save button is clicked, and on this click event, a stored procedure fires and grabs some data from Access that matches the Shipping Report number entered in the data entry part of the app. 1 record is found for each new invoice entered and is then saved to a table called t_groupdata. This record is also displayed in the DGV.
The user can then make any changes to this record in the DGV or add an additional record if needed. Once this is done, they click btnSave to save those changes back to t_groupdata. I am getting multiple records if I save the changes in the DGV and then come back later and make changes to the original Data Entry and use the binding navigator save button. I get double records with each click of the binding navigator save button. Here is my code
VB.NET:
Dim ds1 As New DataSet
Dim strSQLConn2 As String = "Data Source=HERCULES;Initial Catalog=Carcass2;Integrated Security=True"
Dim cn2 As New SqlConnection(strSQLConn2)
Private Sub KILSHEETBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnBtnSave.Click
Dim strSQLConn1 As String = "Data Source=HERCULES;Initial Catalog=ShippingReportData;Integrated Security=True"
Dim cn1 As New SqlConnection(strSQLConn1)
Dim command As SqlCommand = New SqlCommand("sp_CarcCombo", cn1)
cn1.Open()
command.CommandType = CommandType.StoredProcedure
command.Parameters.AddWithValue("@KsID", txtKsId.Text)
command.ExecuteNonQuery()
cn1.Close()
cn1.Dispose()
Dim strSQLConn2 As String = "Data Source=HERCULES;Initial Catalog=Carcass2;Integrated Security=True"
Dim cn2 As SqlConnection = New SqlConnection(strSQLConn2)
Dim da1 As New SqlDataAdapter("SELECT ksID, ShipRptNo, Site, Barn, id, head, weight FROM t_groupdata WHERE ksID = " & txtKsId.Text, cn2)
da1.SelectCommand.CommandType = CommandType.Text
da1.AcceptChangesDuringFill = False
da1.Fill(ds1, "groupdata")
Me.GroupDataList.DataSource = ds1
Me.GroupDataList.DataMember = "groupdata"
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveGroup.Click
Dim da1 As New SqlDataAdapter("SELECT ksID, ShipRptNo, Site, Barn, id, head, weight FROM t_groupdata WHERE ksID = " & txtKsId.Text, cn2)
Dim cb As New SqlCommandBuilder(da1)
da1.Update(ds1, "groupdata")
End Sub
Any explanation or solution to this would be greatly appreciated. I am running out of time and in quite a pickle!