Can't Insert Into Access Table Using .NET

G

Guest

Hi.

This is killing me. I am trying to insert a row into an Access table, but
it's giving me an exception as below.

"Syntax error in INSERT INTO statement."

When I debug and look at the SQL string it is as follows.

"insert into tblCustomer (PropertyType, FirstName, LastName, Address1,
Address2, City, State, Zip, HomePhone, DaytimePhone, MobilePhone, OtherPhone,
Email, Password) values (0, 'Jay', 'Park', '41103 Oakriver Lane', '', 'Las
Vegas', 'CA', '91321', '', '333', '', '', 'Email', 'Password')"

If I copy the above statement in SQL View, it is fine. I just don't get it.
The below is my code.

private int InsertCustomer(OleDbConnection oConn)
{
string sSQL = "insert into tblCustomer (PropertyType, FirstName,
LastName, Address1, Address2, City, State, Zip, HomePhone, DaytimePhone,
MobilePhone, OtherPhone, Email, Password) values (" +
Session["PropertyType"].ToString() + ", '" + Session["FirstName"] + "', '" +
Session["LastName"] + "', '" + Session["Address1"] + "', '" +
Session["Address2"] + "', '" + Session["City"] + "', '" + Session["State"] +
"', '" + Session["ZipCode"] + "', '" + Session["HomePhone"] + "', '" +
Session["DaytimePhone"] + "', '" + Session["MobilePhone"] + "', '" +
Session["OtherPhone"] + "', '" + Session["Email"] + "', '" +
Session["Password"] + "')";
OleDbCommand oCmd = new OleDbCommand(sSQL, oConn);
oCmd.ExecuteNonQuery();

Your input is appreciated.
J
 
G

Guest

Hi,

I think this is because of some datatype mismatch. The front end and
backend databases may not be mapped correctly.

Just a thought!

Thanks,
Dinesh
 
P

Paul Clement

¤ Hi.
¤
¤ This is killing me. I am trying to insert a row into an Access table, but
¤ it's giving me an exception as below.
¤
¤ "Syntax error in INSERT INTO statement."
¤
¤ When I debug and look at the SQL string it is as follows.
¤
¤ "insert into tblCustomer (PropertyType, FirstName, LastName, Address1,
¤ Address2, City, State, Zip, HomePhone, DaytimePhone, MobilePhone, OtherPhone,
¤ Email, Password) values (0, 'Jay', 'Park', '41103 Oakriver Lane', '', 'Las
¤ Vegas', 'CA', '91321', '', '333', '', '', 'Email', 'Password')"
¤
¤ If I copy the above statement in SQL View, it is fine. I just don't get it.
¤ The below is my code.
¤
¤ private int InsertCustomer(OleDbConnection oConn)
¤ {
¤ string sSQL = "insert into tblCustomer (PropertyType, FirstName,
¤ LastName, Address1, Address2, City, State, Zip, HomePhone, DaytimePhone,
¤ MobilePhone, OtherPhone, Email, Password) values (" +
¤ Session["PropertyType"].ToString() + ", '" + Session["FirstName"] + "', '" +
¤ Session["LastName"] + "', '" + Session["Address1"] + "', '" +
¤ Session["Address2"] + "', '" + Session["City"] + "', '" + Session["State"] +
¤ "', '" + Session["ZipCode"] + "', '" + Session["HomePhone"] + "', '" +
¤ Session["DaytimePhone"] + "', '" + Session["MobilePhone"] + "', '" +
¤ Session["OtherPhone"] + "', '" + Session["Email"] + "', '" +
¤ Session["Password"] + "')";
¤ OleDbCommand oCmd = new OleDbCommand(sSQL, oConn);
¤ oCmd.ExecuteNonQuery();
¤
¤ Your input is appreciated.
¤ J


The column name Password is a reserved word. You will need to either enclose it within brackets or
rename it within your SQL statement.


Paul
~~~~
Microsoft MVP (Visual Basic)
 
G

Guest

Hi,

I meant front end and backend datatypes. (not databases)
Sorry for that...

Dinesh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top