0

System.Data.SqlClient をインポートします

Public Class 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 に答える