Can't Insert Into Access Table Using .NET

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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
 
¤ 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)
 
Back
Top