我试图更改绑定到数据网格视图的数据表中的字段,并且当单元格值更改时,将更改写入数据库。代码是这样的:
Public Class Form1
Private TableAdapter As New DSStampsTableAdapters.CountriesTableAdapter
Private MydataTable As New DSStamps.CountriesDataTable
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
TableAdapter.Fill(MydataTable)
DgView1.DataSource = MydataTable
End Sub
Private Sub DgView1_CellValueChanged(sender As Object, e As DataGridViewCellEventArgs) Handles DgView1.CellValueChanged
If DgView1.CurrentCell.OwningColumn.Name = CoMakom Then
Dim MyDataRow As DSStamps.CountriesRow = DirectCast(DgView1.Rows(e.RowIndex).DataBoundItem, DataRowView).Row
TextBox1.Text = MyDataRow.Makom
Try
TableAdapter.Update(MyDataRow)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
MydataTable.Rows.Clear()
TableAdapter.Fill(MydataTable)
End Sub
End Class`
一切正常,但是当我单击button1时,表会重新加载而没有更新。
要绕过这个问题,我用一个更新查询替换了update的调用,女巫更新了数据库,但后来在程序中引发了并发冲突。
此表已在其他几个类中进行了更新,没有任何问题,仅此从主目录完成的更新不起作用。
此编码有什么问题? 需要帮助!