0

导入 System.Data.SqlClient

公共类 Form1 Dim cn As SqlConnection Dim ds As DataSet Dim adapter As SqlDataAdapter Dim eleveBindingSource As BindingSource Dim builder As SqlCommandBuilder

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    cn = New SqlConnection("Data source=.; initial catalog=tp4_ado; integrated security=sspi")
    ds = New DataSet()
    eleveBindingSource = New BindingSource
    adapter = New SqlDataAdapter("Select * from Eleve", cn)
    adapter.Fill(ds, "Eleve")
    eleveBindingSource.DataSource = ds
    eleveBindingSource.DataMember = "Eleve"
    DataGridView1.DataSource = eleveBindingSource
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    adapter.Update(ds.Tables("Eleve"))
End Sub

结束类

4

1 回答 1

0

UpdateCommand问题是我在修改时没有初始化DataGridView

所以我必须在更新之前添加此代码DataSet

builder = New SqlCommandBuilder(adapter)
于 2013-01-24T11:10:16.920 回答