Inserting MS Access Row Into Database using vb.net

DidIReallyWriteThat picture DidIReallyWriteThat · Feb 23, 2014 · Viewed 19.9k times · Source

So im trying to add fields to a database. It is .mdb database, microsoft access.

The Name of the table is Contacts.

Dim con As New OleDb.OleDbConnection
    Dim dbProvider As String
    Dim dbSource As String
    Dim ds As New DataSet
    Dim da As OleDb.OleDbDataAdapter
    Dim sql As String

    dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
    dbSource = "Data Source= C:\Users\Owner\Desktop\Contacts.mdb"

    con.ConnectionString = dbProvider & dbSource

    con.Open()

    sql = "INSERT INTO Contacts (FName, LName, Age, Address Line 1, Address Line 2, City, State, Zip, Home Phone, Work Phone, Email, Sex) VALUES (a, b, c,d,e,f,g,h,i,j,k)"
    da = New OleDb.OleDbDataAdapter(Sql, con)
    da.Fill(ds, "Contacts")

My Error is Syntax error in INSERT INTO statement. Which makes no sense, whatsoever. What am i doing wrong?

EDIT* I solvedmy riginal problem by adding [] around certian fields as suggested, thanks. Now I am getting...

No value given for one or more required parameters.

The database has a primary ID field that autoincrements, does this change anything?

Answer

Luc Morin picture Luc Morin · Feb 23, 2014

Put column names with spaces between squares brackets []

For example [Address Line 1]

Cheers