473,395 Members | 2,006 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Can't Insert Into Access Table Using .NET

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

--
Be Cool!
Jul 21 '05 #1
5 1494
Hi BeCool,

Although you will see probably all messages about SQL server injections,
which has of course nothing to do with your access database, is this normal
way to go (it is not the recordset way from ADODB).

http://msdn.microsoft.com/library/de...eterstopic.asp

I hope this helps,

Cor
Jul 21 '05 #2
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

"Cor Ligthert" wrote:
Hi BeCool,

Although you will see probably all messages about SQL server injections,
which has of course nothing to do with your access database, is this normal
way to go (it is not the recordset way from ADODB).

http://msdn.microsoft.com/library/de...eterstopic.asp

I hope this helps,

Cor

Jul 21 '05 #3
On Wed, 11 May 2005 18:30:02 -0700, thejackofall <th**********@discussions.microsoft.com> wrote:

¤ 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)
Jul 21 '05 #4
Hi,

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

Dinesh
"thejackofall" wrote:
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

--
Be Cool!

Jul 21 '05 #5
Thanks.

J

--
Be Cool!
"Paul Clement" wrote:
On Wed, 11 May 2005 18:30:02 -0700, thejackofall <th**********@discussions.microsoft.com> wrote:

¤ 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)

Jul 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: ImraneA | last post by:
Hi there I had pleasure of upsizing Access v97 db to Access v2K/SQL 2K. Wish to provide some knowledge gained back to community - hopefully help others. 1.Question how do you test stored...
8
by: Bri | last post by:
Greetings, I'm having a very strange problem in an AC97 MDB with ODBC Linked tables to SQL Server 7. The table has an Identity field and a Timestamp field. The problem is that when a new record...
0
by: crypto_solid via AccessMonster.com | last post by:
I have been using a SQL database with a VB5 frontend for about 5 years. Works well. Unfortunately I don't have access to the source code. I was tasked with implementing a "job entry" application...
1
by: Abareblue | last post by:
I have no clue on how to insert a record into access. here is the whole thing using System; using System.Drawing; using System.Collections; using System.ComponentModel;
1
by: geodev | last post by:
I’m copying data across from an Access database to an MSDE database through the use of some vb.net code. Unfortunately the application crashes when it goes to copy across data, in particular...
2
by: Geoffrey KRETZ | last post by:
Hello, I'm wondering if the following behaviour is the correct one for PostGreSQL (7.4 on UNIX). I've a table temp_tab with 5 fields (f1,f2,f3,...),and I'm a launching the following request :...
3
by: MP | last post by:
Hi Posted this several hours ago to another ng but it never showed up thought i'd try here. using vb6, ado, .mdb, jet4.0, no access given table tblJob with field JobNumber text(10) 'The...
3
by: Mike Charney | last post by:
I have a two part question: First I want to insert data into a table and I am using the following command: INSERT INTO tblmain SELECT field1, field2, etc... FROM tblimport WHERE ?????? The...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
6
by: lenygold via DBMonster.com | last post by:
Hi everybody: What is the best way to I have 10 tables with similar INSERT requiremnts. INSERT INTO ACSB.VAATAFAE WITH AA(AA_TIN, AA_FILE_SOURCE_CD, .AA_TIN_TYP) AS ( SELECT AA_TIN,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.