1

我一直在研究这个问题一段时间,看不出我做错了什么。

我想将更改从 DataSet( ds.Tables("Login") ) 保存到物理数据库 ( Data Source='|DataDirectory|\MyDatabase.accdb )。但它不能正常工作。数据未保存在物理数据库中。

任何想法如何解决它?

 Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles txtUsername.Click
    Dim ds As New DataSet()
    Dim dt As DataTable
    ds.Tables.Add(New DataTable("Login"))
    Dim connStr As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='|DataDirectory|\MyDatabase.accdb'"
    Dim sqlStr As String = "SELECT * FROM Login"
    Dim dataAdapter As New OleDb.OleDbDataAdapter(sqlStr, connStr)
    dataAdapter.Fill(ds.Tables("Login"))

    dt = ds.Tables("Login")

    Dim dr As DataRow
    dr = dt.NewRow()
    dr("Username") = txtUserName.Text
    dr("Password") = txtPassword.Text

    dt.Rows.Add(dr)
    ds.AcceptChanges()
    dataAdapter.Update(ds.Tables("Login"))
End Sub
4

1 回答 1

0

Look at this article and particularly step 7 which states you will need to set the UpdateCommand.

https://support.microsoft.com/en-us/kb/301248

于 2015-05-01T10:52:57.833 回答