Ok, first off I am using vb.net to access a local database in a very simple
customer database program. I started off using the oledb data adapter wizard
and the query builder to make my statements. The default Insert statement it
provided was simple. "INSERT INTO customertable(phone, first, last)
VALUES(?,?,?)" When I execute the app, I get an error "Syntax error in INSERT
INTO statement" So, after playing around with the query builder, I found that
everything works just fine if I only insert one field. So I decide to code the
whole thing out to see if that works and it ends up doing the same thing. It
works fine for one field "INSERT INTO customertable(phone) VALUES(?)" Even if I set "VALUES(1,2,3) it does the same thing. It works fine with "VALUES(1)" I've
pasted my code below hoping someone could please help me out. Thanks!
Jake
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim sqlCustomerInsert,
insPhone, insFirst, insLast As String
Dim icount As Integer
Dim con As New OleDb.OleDbConnection
Dim cmd As OleDb.OleDbCommand
Dim dsCustomerInsert
As New DataSet
Dim drNewRow
As DataRow
Dim daCustomerInsert
As
OleDb.OleDbDataAdapter
sqlCustomerInsert = "insert into CustomerTable(Phone, First) values('" &
txtPhone.Text & "', '" & txtFirst.Text & "','" & txtLast.Text
& "')"
con.ConnectionString = "Jet OLEDB:Global Partial Bulk Ops=2;Jet
OLEDB:Registry Path=;Jet OLEDB:Database L" & _
"ocking Mode=1;Data Source=""C:\Databases\CustomerDB.mdb"";Jet OLEDB:Engine
Type=5;" & _
"Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet
OLEDB:SFP=Fals" & _
"e;persist security info=False;Extended Properties=;Mode=Share Deny None;Jet
OLED" & _
"B:Encrypt Database=False;Jet OLEDB:Create System Database=False;Jet
OLEDB:Don't " & _
"Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica
Repair=False;User" & _
" ID=Admin;Jet OLEDB:Global Bulk Transactions=1"
daCustomerInsert = New
OleDb.OleDbDataAdapter(sqlCustomerInsert, con)
Try
con.Open()
cmd = New
OleDb.OleDbCommand(sqlCustomerInsert, con)
icount = cmd.ExecuteNonQuery()
MessageBox.Show(icount)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try