BindingSource的EndEdit方法與DataAdapter的Update,在提交到數據庫時候需要注意所綁定的DataTable是否直接關聯DataSet與DataAdapter,否側無法正常提交到數據庫文件,只能提交到Table裏面。隨後需要自己寫方法從Table提交到數據庫。
若使用的Table關聯了DataSet與DataAdapter,則BindingSource的EndEdit方法與DataAdapter的Update可正常提交。
Code:
Dim mdt As DataTablePublic Sub DoWork()
'根據Id加載方案列表
If TParam.WellProperty Is Nothing Then
Exit Sub
End If
Dim sqls As String = String.Format("select * from designresult where id='{0}'", TParam.WellProperty.ID)
mdt = SQLHelper.Query(sqls, "designResult")
bSource.DataSource = mdt
bNavigator.BindingSource = bSource
dgv1.DataSource = bSource
End Sub
Try
dgv1.EndEdit()
bSource.EndEdit()
'這裏datasource的endedit只是提交到datatable,因爲這個dt並不是直接關聯dataAdapter的,因此endedit無法提交到實體數據庫
SQLHelper.ExecuteDT(mdt, "designresult")
Catch ex As Exception
Common.ExcNow(ex)
End Try
End Sub