我将Access数据库连接到Visual Studios中的Web表单,但是当尝试更新数据库中的记录时,它会出现语法错误。
Public Class Form1
Dim con As New OleDb.OleDbConnection
Dim da As New OleDb.OleDbDataAdapter
Dim ds As New DataSet
Dim sql As String
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source= StudentDatabase.mdb"
sql = "SELECT * FROM StudentDatabase"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "StudentDatabase")
Label1.Text = ds.Tables("StudentDatabase").Rows(1).Item("Student First Name")
con.Open()
con.Close()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim cb As New OleDb.OleDbCommandBuilder(da)
ds.Tables("StudentDatabase").Rows(1).Item("Student First Name") = TextBox1.Text
da.Update(ds, "StudentDatabase")
End Sub
End Class
它应该使用在文本框中编写的内容更新数据库,但是会出现语法错误。