I've previously posted about my difficulties here, here, here and here.
A year since I've started struggling with this problem, it still hasn't been fully resolved. 90% of the time, it works fine. 10% of the time, it doesn't, and I cannot figure out why.
I have a datagridview with several columns, all of which are read only by default. When the user clicks a toggle button, three columns (Start Date, Complete Date, and Load Date) are unlocked for editing. When clicking in one of those cells, a custom calendar control appears. When a date is selected in that control, it is inserted into the corresponding cell in the datagridview. This part works fine.
What is hit-or-miss is whether or not the update to the database actually goes through.
Here is my update procedure:
I call the UpdateScheduleData procedure on DataGridView_CellEndEdit, BindingSource_PositionChanged and DataGridView_RowValidated. Yet sometimes (and I can find no rhyme or reason as to why) the update doesn't make it to the database, even when the dataadapter.update call is made with a datatable that reflects the changed dates.
What am I doing wrong at this point?
A year since I've started struggling with this problem, it still hasn't been fully resolved. 90% of the time, it works fine. 10% of the time, it doesn't, and I cannot figure out why.
I have a datagridview with several columns, all of which are read only by default. When the user clicks a toggle button, three columns (Start Date, Complete Date, and Load Date) are unlocked for editing. When clicking in one of those cells, a custom calendar control appears. When a date is selected in that control, it is inserted into the corresponding cell in the datagridview. This part works fine.
What is hit-or-miss is whether or not the update to the database actually goes through.
Here is my update procedure:
vb Code:
Public Sub UpdateScheduleData() Try If IgnoreInput Then Exit Sub Using Conn = GetConnect() Conn.Open() cmdSQL = New SqlCommand("Update Orders_Open Set JobStartDate = @JobStartDate, JobCompleteDate = @JobCompleteDate, LoadDate = @LoadDate, Status = @Status Where OrderID = @OrderID", daSchedule.SelectCommand.Connection) cmdSQL.Parameters.Add(New SqlParameter("@OrderID", SqlDbType.VarChar)) cmdSQL.Parameters("@OrderID").Value = dgSchedule.Rows(LastEditedRow).Cells("Order ID").Value.ToString cmdSQL.Parameters.Add(New SqlParameter("@JobStartDate", SqlDbType.VarChar)) If dgSchedule.Rows(LastEditedRow).Cells("Job Start").Value.ToString <> "" Then cmdSQL.Parameters("@JobStartDate").Value = dgSchedule.Rows(LastEditedRow).Cells("Job Start").Value.ToString Else cmdSQL.Parameters("@JobStartDate").Value = DBNull.Value End If cmdSQL.Parameters.Add(New SqlParameter("@JobCompleteDate", SqlDbType.VarChar)) If dgSchedule.Rows(LastEditedRow).Cells("Job Complete").Value.ToString <> "" Then cmdSQL.Parameters("@JobCompleteDate").Value = dgSchedule.Rows(LastEditedRow).Cells("Job Complete").Value.ToString Else cmdSQL.Parameters("@JobCompleteDate").Value = DBNull.Value End If cmdSQL.Parameters.Add(New SqlParameter("@LoadDate", SqlDbType.VarChar)) If dgSchedule.Rows(LastEditedRow).Cells("Load Date").Value.ToString <> "" Then cmdSQL.Parameters("@LoadDate").Value = dgSchedule.Rows(LastEditedRow).Cells("Load Date").Value.ToString Else cmdSQL.Parameters("@LoadDate").Value = DBNull.Value End If cmdSQL.Parameters.Add(New SqlParameter("@Status", SqlDbType.Int)) cmdSQL.Parameters("@Status").Value = dgSchedule.Rows(LastEditedRow).Cells("Status").Value daSchedule.UpdateCommand = cmdSQL daSchedule.Update(dtSchedule) End Using Catch ex As Exception MessageBox.Show("Error: " & ex.Source & ": " & ex.Message, System.Reflection.MethodInfo.GetCurrentMethod.ToString, MessageBoxButtons.OK) LogErrors(System.Reflection.MethodInfo.GetCurrentMethod.ToString & " -- " & ex.Message) End Try End Sub
I call the UpdateScheduleData procedure on DataGridView_CellEndEdit, BindingSource_PositionChanged and DataGridView_RowValidated. Yet sometimes (and I can find no rhyme or reason as to why) the update doesn't make it to the database, even when the dataadapter.update call is made with a datatable that reflects the changed dates.
What am I doing wrong at this point?