Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
820 views
in Technique[技术] by (71.8m points)

sql - Inserting MS Access Row Into Database using vb.net

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:UsersOwnerDesktopContacts.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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Put column names with spaces between squares brackets []

For example [Address Line 1]

Cheers


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...