将记录插入Access数据库

时间:2013-09-21 16:11:41

标签: sql vb.net visual-studio-2010 oledb

我想在访问中插入变量,但我收到此错误消息: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

1 个答案:

答案 0 :(得分:1)

应该是......

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

最好使用参数..来保证数据安全..