0

我想在访问中插入变量,但我收到此错误消息: OleDBExeception 未处理;没有为一个或多个必需参数指定值。谁能告诉我错误在哪里?

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim strSurname, strName As String
    strSurname = Me.TextBox1.Text
    strName = Me.TextBox2.Text

    Dim myConnection As OleDbConnection
    Dim ConString As String = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source= Dbtry.accdb ; Persist Security Info=True"
    myConnection = New OleDbConnection(ConString)
    myConnection.Open()
    Dim sqlQry As String

    sqlQry = "INSERT INTO BookingFly (ID,Client_Name, Client_Surname) VALUES(1,strSurname, strName)"

    Dim cmd As New OleDbCommand(sqlQry, myConnection)
    cmd.ExecuteNonQuery()

End Sub
4

1 回答 1

1

它应该是 ..

sqlQry = "INSERT INTO BookingFly (ID,Client_Name, Client_Surname) VALUES(1, '" & strSurname & "','" & strName "')"

为了您的数据安全,最好使用参数 ..

于 2013-09-21T16:16:35.483 回答