导入System.Data.SqlClient
Public Class Form1 Dim cn As SqlConnection Dim ds As DataSet Dim adapter As SqlDataAdapter Dim eleveBindingSource作为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
结束班
答案 0 :(得分:0)
问题是当我修改UpdateCommand
DataGridView
所以我必须在更新DataSet
之前添加此代码:
builder = New SqlCommandBuilder(adapter)