我正在尝试编写一个可以将数据写入 Access DB 的程序,但我不断收到错误“INSERT INTO 语句中的语法错误”。
FirstLast
是表的名称;First
并且Last
是其中的列。
Imports System.Data.OleDb
Public Class Form1
Dim theConnectionString As New OleDbConnection
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
theConnectionString.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\user\Documents\Database1.accdb"
Dim cmd As OleDbCommand = New OleDbCommand("INSERT INTO FirstLast (First, Last) VALUES (@First, TextBox1.text)", theConnectionString)
cmd.Parameters.Add("@First", OleDbType.Char, 255).Value = TextBox1.Text
cmd.Parameters.Add("@Last", OleDbType.Char, 255).Value = TextBox1.Text
Try
theConnectionString.Open()
cmd.ExecuteNonQuery()
Catch ex As Exception
Throw ex
Finally
theConnectionString.Close()
End Try
End Sub
End Class