Question How to use Insert

JM Ribeiro

New member
Joined
Mar 4, 2009
Messages
1
Programming Experience
3-5
Hi

I'm trying to use Insert to save the data into an Access DB.
When using this coed I get a Syntax error.
Can anyone help I'm tiered of searching google for an answer.
Thanks

This is the coed I'm using.


m_Customer = comCustomer.ExecuteReader
Dim adapter As New OleDb.OleDbDataAdapter
Dim customer_dt As New DataTable
customer_dt.Load(m_Customer)


m_Notes = comdNotes.ExecuteReader
Dim Notes_dt As New DataTable
Notes_dt.Load(m_Notes)

Dim sql As String = "Insert Into Customer_tbl(Date,PONumber,First Name,Last Name,Address,City,Civic)values(m_today,txtOrderEntry,txtFirstName,txtLastName,TxtAddress,txtCity,txtCivic)"
Dim cmd As New OleDb.OleDbCommand(sql, con)
cmd.executenonquery()
 
Did you start programming with PHP? VB does not parse variable names in double quotes. So you need to concanate your string with "&"
VB.NET:
Expand Collapse Copy
mystring = "Atext " & a_variable & " another text " & txtField.txt
 
Please don't instruct newbies to use string concatenation to build SQLs

JMR, do this:

VB.NET:
Expand Collapse Copy
Dim cmd As OleDbCommand = New OleDbCommand("Insert Into Customer_tbl(Date,PONumber,First Name,Last Name,Address,City,Civic)values(?,?,?,?,?,?,?)")
cmd.Parameters.AddWithValue("date", m_today)
cmd.Parameters.AddWithValue("ponumber", txtOrderEnt)
cmd.Parameters.AddWithValue("firstname",txtFirstName)
... and so on

For more info, read the PQ link in my signature
 
Last edited:
Back
Top