I'm working on this feature were i save text from a textbox on my form to a access database file. With the click on my "store" button I want to save the text in the corresponding textbox fields to the fields in my access database for searching and retrieving purposes. Im doing this in VB
The problem I run into is the INSERT TO error with my "store" button Any help or insight as to why im getting error would be greatly appreciated.
here is my code:
Dim con As System.Data.OleDb.OleDbConnection
Dim cmd As System.Data.OleDb.OleDbCommand
Dim dr As System.Data.OleDb.OleDbDataReader
Dim sqlStr As String
Private Sub btnStore_Click(sender As Object, e As EventArgs) Handles btnStore.Click
    con = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Eric\Documents\SPC1.2.accdb")
    con.Open()
    MsgBox("Initialized")
    sqlStr = "INSERT INTO Master FADV Calll info  (First Name, Last Name, 
       Phone Number, Email, User Id) values (" & txtFirstName.Text & " ' ,'" &
       txtLastName.Text & "','" & txtPhone.Text & "', '" & txtEmail.Text & "', '" &
       txtUserID.Text & "', '" & txtOtherOptionTxt.Text & "','" 
       & txtCallDetail.Text & "');"
    cmd = New OleDb.OleDbCommand(sqlStr, con)
    cmd.ExecuteNonQuery()   <------- **IM RECIVING THE ERROR HERE** 
    MsgBox("Stored")
    ''pass ther parameter as sq; query, con " connection Obj)"
    con.Close()
So I tried to clean up my code a little, I didn't use paramerters like you recommended yet so maybe that is why I am still receiving the error. I figured this would work since it was a little cleaner
sqlStr = "INSERT INTO Master FADV Calll info(First Name, Last Name, Phone Number,
 Email, User Id,Notes) values (@First Name, @Last Name, @Phone Number,@ Email,
 @UserId,@Notes)"
    cmd = New OleDb.OleDbCommand(sqlStr, con)
    cmd.ExecuteNonQuery()'
Now by parameters do you mean something along the lines of this 'cmdInsert.Parameters.Add("@FirstName", Data.SqlDbType.NVarChar).Value = FirstName'
im still getting this crazy error its making me want to bang my head against a wall. I do apologize for bugging you on such a meager issue, but please bear with me. I am receiving this error message here is my code Syntax error (missing operator) in query expression '@First Name'.
but even before I was still getting an input error at the cmd.ExecuteNonQuery() line.
'Dim SQL As String = "INSERT INTO [Master FADV Calll info] Values (@First Name, @Last Name, @Phone Number,)"
    Using cmd As New OleDbCommand(SQL, con)
        cmd.Parameters.AddWithValue("@First Name", txtFirstName.Text)
        cmd.Parameters.AddWithValue("@Last Name", txtLastName.Text)
        cmd.Parameters.AddWithValue("@Phone Number", txtPhone.Text)
        ' etc
        cmd.ExecuteNonQuery()
    End Using'
I fianaly got it to work. here is my code
' con = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Eric\Documents\Fadv.accdb") con.Open()
    Dim SQL As String = "INSERT INTO [info] ([FirstName], [LastName], [Phone#]) Values (?, ?, ?)"
    Using cmd As New OleDbCommand(Sql, con)
        cmd.Parameters.AddWithValue("@p1", txtFirstName.Text)
        cmd.Parameters.AddWithValue("@p2", txtLastName.Text)
        cmd.Parameters.AddWithValue("@p3", txtPhone.Text)
        ' etc
        cmd.ExecuteNonQuery()
        con.Close()
    End Using
'
 
     
     
    