Trying to Insert Text to Access Database with ExecuteNonQueryin VB

Posted by user3673701 on Stack Overflow See other posts from Stack Overflow or by user3673701
Published on 2014-05-27T02:29:25Z Indexed on 2014/05/27 3:28 UTC
Read the original article Hit count: 175

Filed under:
|
|

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()'

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about insert