Private Sub UpdateGrid() Try If Me.DataGridView1.IsCurrentCellDirty = True Then Me.DataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit) Me.BindingSource1.EndEdit() End If Dim myBuilder As SqlCommandBuilder = New SqlCommandBuilder(adapter) myBuilder.GetUpdateCommand() adapter.UpdateCommand = myBuilder.GetUpdateCommand() For Each row As DataRow In table.Rows If row.RowState = DataRowState.Modified Then row("UserID") = USER.ID End If Next adapter.Update(table) Catch e As SqlException Debug.Print("SQL Err - " & e.ErrorCode) Catch ex As Exception Debug.Print(ex.Message) End Try End Sub
Visual Studio 2010 - VB.NET
My application is used in a manufacturing production environment.
One essential activity is controlled/changed by use of a DataGridView control.
It appears that after updating this control, somehow (on rare occasions) a blank space is being appended to one of the underlying columns in SQL server. The code that loads and updates the control is attached. the field affected is called sterileNo.
Has anyone got any suggestions? Would I be better to use code to explicitly update my database for each ro rather than using a BindingConrol?
Thanks
Private Sub SetDataGridView()
Try
' Set up the DataGridView.
With Me.DataGridView1
.AutoGenerateColumns = True
' Set up the data source.
BindingSource1.DataSource = _
GetData("SELECT * FROM sterilecontrol WHERE sterileno='" & _
Trim$(Me.txtSterileNo.Text) & "' AND steriledate='" & Me.dtpSterileDate.Text & "'")
.DataSource = BindingSource1
' Automatically resize the visible rows.
.AutoSizeRowsMode = _
DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
' Set the DataGridView control's border.
.BorderStyle = BorderStyle.Fixed3D
' Put the cells in edit mode when user enters them.
.EditMode = DataGridViewEditMode.EditOnEnter
End With
Catch ex As SqlException
MsgBox(ex.Message)
End Try
End Sub<input id="238de6cd-29fe-44e1-a14e-6dce751b3fce_attachments" type="hidden" value="" />