473,399 Members | 4,177 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,399 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 1495
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.