0

DataGridView に加えられた変更をデータベース MS SQL CE に保存したいのですが、変更がデータベースに保存されません....

これはコード(VB.net)です:

    Private Sub Form1_Load(ByVal sender As System.Object, 
        ByVal e As System.EventArgs) handles MyBase.Load

        Dim con As SqlCeConnection = New SqlCeConnection(@"Data  Source=C:\Users\utente\Documents\test.sdf")

        Dim cmd As SqlCeCommand = New SqlCeCommand("SELECT * FROM mytable", con)

        con.Open()
        myDA = New SqlCeDataAdapter(cmd)
        Dim builder As SqlCeCommandBuilder = New SqlCeCommandBuilder(myDA)
        myDataSet = New DataSet()
        myDA.Fill(myDataSet, "MyTable")
        DataGridView1.DataSource = myDataSet.Tables("MyTable").DefaultView
        con.Close()
        con = Nothing

    End Sub



    Private Sub edit_rec()

        Dim txt1, txt2 As String
        Dim indice As Integer = DataGridView1.CurrentRow.Index

        txt1 = DataGridView1(0, indice).Value.ToString '(0 is the first column of datagridview)
        txt2 = DataGridView1(1, indice).Value.ToString '(1 is the second)        MsgBox(txt1 + "  " + txt2)
        '
        DataGridView1(0, indice).Value = "Pippo"
        DataGridView1(1, indice).Value = "Pluto"
        '
        Me.Validate()
        Me.myDA.Update(Me.myDataSet.Tables("MyTable"))
        Me.myDataSet.AcceptChanges()
        '
    End Sub

ご提案ありがとうございます。

4

3 に答える 3

0

変更をコミットする myDA.Update を使用する必要があります。これは、行っている変更がそのデータセットのローカル インスタンスで行われるためです。したがって、他の変数と同じように破棄されます。

...あなたのedit_recサブでそれを見ることができますが、それを呼んでいるのは何ですか-あなたが投稿したコードには何もありません。

于 2013-08-23T14:17:37.603 に答える