473,396 Members | 1,917 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,396 software developers and data experts.

SQL INSERT syntax error, but the statement is correct!

hello! one of my forms communicates with a database, and is
supposed to add a row to a table using an Insert
statement... however, I get a 'oledb - syntax error'
exception... I have double checked, and the insert works
fine (tried to use it from access)... im using visual C#
express 2k5... what could be wrong? thanks!
Nov 16 '05 #1
7 6628
kosta,

I would guess that there actually is something wrong with the statement,
or how you are executing it. Can you show the code that you have which is
trying to perform the insert?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"kosta" <an*******@discussions.microsoft.com> wrote in message
news:0b****************************@phx.gbl...
hello! one of my forms communicates with a database, and is
supposed to add a row to a table using an Insert
statement... however, I get a 'oledb - syntax error'
exception... I have double checked, and the insert works
fine (tried to use it from access)... im using visual C#
express 2k5... what could be wrong? thanks!

Nov 16 '05 #2
Hi kosta,

Could you please post the sql statement. Which is the db you are using - is
it access?

Regards,
Rakesh Rajan

"kosta" wrote:
hello! one of my forms communicates with a database, and is
supposed to add a row to a table using an Insert
statement... however, I get a 'oledb - syntax error'
exception... I have double checked, and the insert works
fine (tried to use it from access)... im using visual C#
express 2k5... what could be wrong? thanks!

Nov 16 '05 #3
Hi,

Probably you have a ' somewhere used as a parameter, for any further help
post the code and the exception message

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"kosta" <an*******@discussions.microsoft.com> wrote in message
news:0b****************************@phx.gbl...
hello! one of my forms communicates with a database, and is
supposed to add a row to a table using an Insert
statement... however, I get a 'oledb - syntax error'
exception... I have double checked, and the insert works
fine (tried to use it from access)... im using visual C#
express 2k5... what could be wrong? thanks!

Nov 16 '05 #4
Yes, it is an access 2000 database.
here is the statement:

INSERT INTO Partyers (Sex, Last, First, CPhone, Phone,
City, BDay, Car, PicPath, FPotential, TPotential,
PartyCities) Values (False, '', '', '', '', '', '10/16/2004
12:17:22 AM', False, '', '', '', '')

when I use it from access, it goes file...

here is the code I use to Add it:

public static int ANum(String sql)
{
OleDbConnection con = new OleDbConnection();
con.ConnectionString =
ConfigurationSettings.AppSettings["conString"];
OleDbCommand cmd = new OleDbCommand(sql,con);
con.Open();
cmd.ExecuteNonQuery();
string identity = "select @@identity";
cmd.CommandText = identity;
int id = (int)cmd.ExecuteScalar();
con.Close();
return id;
}

and the exception:
{"Syntax error in INSERT INTO statement."}
[System.Data.OleDb.OleDbException]: {"Syntax error in
INSERT INTO statement."}
Data: {System.Collections.ListDictionaryInternal}
HelpLink: null
InnerException: null
Message: "Syntax error in INSERT INTO statement."
Source: "Microsoft JET Database Engine"
StackTrace: " at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextE rrorHandling(OleDbHResult
hr)\r\n at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextF orSingleResult(tagDBPARAMS
dbParams, Object& executeResult)\r\n at
System.Data.OleDb.OleDbCommand.ExecuteCommandText( Object&
executeResult)\r\n at
System.Data.OleDb.OleDbCommand.ExecuteCommand(Comm andBehavior
behavior, Object& executeResult)\r\n at
System.Data.OleDb.OleDbCommand.ExecuteReaderIntern al(CommandBehavior
behavior, String method)\r\n at
System.Data.OleDb.OleDbCommand.ExecuteNonQuery()\r \n at
SQL.Connect.ANum(String sql) in f:\\my documents\\visual
studio\\projects\\connect\\connect.cs:line 63\r\n at
SQLStatements.PartiesDB.AddPartier(Boolean Sex, String
LName, String FName, String CPhone, String Phone, String
City, DateTime BDay, Boolean Car, String PicPath, String
PotentialClient, String PotentialTripper, String PCities)
in f:\\my documents\\visual
studio\\projects\\sqlstatements\\partiersdb.cs:lin e 20\r\n
at DataBase.Partyer
Update.Add() in F:\\My Documents\\Visual
Studio\\Projects\\Database\\PartyerUpdate.cs:line 35"
TargetSite: {Void
ExecuteCommandTextErrorHandling(System.Data.OleDb. OleDbHResult)}
thanks a lot in advance! (and to those that already responded!)
Kosta.
-----Original Message-----
Hi kosta,

Could you please post the sql statement. Which is the db you are using - is it access?

Regards,
Rakesh Rajan

"kosta" wrote:
hello! one of my forms communicates with a database, and is
supposed to add a row to a table using an Insert
statement... however, I get a 'oledb - syntax error'
exception... I have double checked, and the insert works
fine (tried to use it from access)... im using visual C#
express 2k5... what could be wrong? thanks!

.

Nov 16 '05 #5
it is an access 2000 database.
here is the statement:

INSERT INTO Partyers (Sex, Last, First, CPhone, Phone,
City, BDay, Car, PicPath, FPotential, TPotential,
PartyCities) Values (False, '', '', '', '', '', '10/16/2004
12:17:22 AM', False, '', '', '', '')

when I use it from access, it goes file...

here is the code I use to Add it:

public static int ANum(String sql)
{
OleDbConnection con = new OleDbConnection();
con.ConnectionString =
ConfigurationSettings.AppSettings["conString"];
OleDbCommand cmd = new OleDbCommand(sql,con);
con.Open();
cmd.ExecuteNonQuery();
string identity = "select @@identity";
cmd.CommandText = identity;
int id = (int)cmd.ExecuteScalar();
con.Close();
return id;
}

and the exception:
{"Syntax error in INSERT INTO statement."}
[System.Data.OleDb.OleDbException]: {"Syntax error in
INSERT INTO statement."}
Data: {System.Collections.ListDictionaryInternal}
HelpLink: null
InnerException: null
Message: "Syntax error in INSERT INTO statement."
Source: "Microsoft JET Database Engine"
StackTrace: " at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextE rrorHandling(OleDbHResult
hr)\r\n at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextF orSingleResult(tagDBPARAMS
dbParams, Object& executeResult)\r\n at
System.Data.OleDb.OleDbCommand.ExecuteCommandText( Object&
executeResult)\r\n at
System.Data.OleDb.OleDbCommand.ExecuteCommand(Comm andBehavior
behavior, Object& executeResult)\r\n at
System.Data.OleDb.OleDbCommand.ExecuteReaderIntern al(CommandBehavior
behavior, String method)\r\n at
System.Data.OleDb.OleDbCommand.ExecuteNonQuery()\r \n at
SQL.Connect.ANum(String sql) in f:\\my documents\\visual
studio\\projects\\connect\\connect.cs:line 63\r\n at
SQLStatements.PartiesDB.AddPartier(Boolean Sex, String
LName, String FName, String CPhone, String Phone, String
City, DateTime BDay, Boolean Car, String PicPath, String
PotentialClient, String PotentialTripper, String PCities)
in f:\\my documents\\visual
studio\\projects\\sqlstatements\\partiersdb.cs:lin e 20\r\n
at DataBase.Partyer
Update.Add() in F:\\My Documents\\Visual
Studio\\Projects\\Database\\PartyerUpdate.cs:line 35"
TargetSite: {Void
ExecuteCommandTextErrorHandling(System.Data.OleDb. OleDbHResult)}
thanks a lot in advance! (and to those that already responded!)
Kosta.
-----Original Message-----
Message unavailable

Nov 16 '05 #6
it is an access 2000 database.
here is the statement:

INSERT INTO Partyers (Sex, Last, First, CPhone, Phone,
City, BDay, Car, PicPath, FPotential, TPotential,
PartyCities) Values (False, '', '', '', '', '', '10/16/2004
12:17:22 AM', False, '', '', '', '')

when I use it from access, it goes file...

here is the code I use to Add it:

public static int ANum(String sql)
{
OleDbConnection con = new OleDbConnection();
con.ConnectionString =
ConfigurationSettings.AppSettings["conString"];
OleDbCommand cmd = new OleDbCommand(sql,con);
con.Open();
cmd.ExecuteNonQuery();
string identity = "select @@identity";
cmd.CommandText = identity;
int id = (int)cmd.ExecuteScalar();
con.Close();
return id;
}

and the exception:
{"Syntax error in INSERT INTO statement."}
[System.Data.OleDb.OleDbException]: {"Syntax error in
INSERT INTO statement."}
Data: {System.Collections.ListDictionaryInternal}
HelpLink: null
InnerException: null
Message: "Syntax error in INSERT INTO statement."
Source: "Microsoft JET Database Engine"
StackTrace: " at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextE rrorHandling(OleDbHResult
hr)\r\n at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextF orSingleResult(tagDBPARAMS
dbParams, Object& executeResult)\r\n at
System.Data.OleDb.OleDbCommand.ExecuteCommandText( Object&
executeResult)\r\n at
System.Data.OleDb.OleDbCommand.ExecuteCommand(Comm andBehavior
behavior, Object& executeResult)\r\n at
System.Data.OleDb.OleDbCommand.ExecuteReaderIntern al(CommandBehavior
behavior, String method)\r\n at
System.Data.OleDb.OleDbCommand.ExecuteNonQuery()\r \n at
SQL.Connect.ANum(String sql) in f:\\my documents\\visual
studio\\projects\\connect\\connect.cs:line 63\r\n at
SQLStatements.PartiesDB.AddPartier(Boolean Sex, String
LName, String FName, String CPhone, String Phone, String
City, DateTime BDay, Boolean Car, String PicPath, String
PotentialClient, String PotentialTripper, String PCities)
in f:\\my documents\\visual
studio\\projects\\sqlstatements\\partiersdb.cs:lin e 20\r\n
at DataBase.Partyer
Update.Add() in F:\\My Documents\\Visual
Studio\\Projects\\Database\\PartyerUpdate.cs:line 35"
TargetSite: {Void
ExecuteCommandTextErrorHandling(System.Data.OleDb. OleDbHResult)}
thanks a lot in advance! (and to those that already responded!)
Kosta.
-----Original Message-----
kosta,

I would guess that there actually is something wrong with the statement, or how you are executing it. Can you show the code that you have which is trying to perform the insert?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"kosta" <an*******@discussions.microsoft.com> wrote in message news:0b****************************@phx.gbl...
hello! one of my forms communicates with a database, and is
supposed to add a row to a table using an Insert
statement... however, I get a 'oledb - syntax error'
exception... I have double checked, and the insert works
fine (tried to use it from access)... im using visual C#
express 2k5... what could be wrong? thanks!

.

Nov 16 '05 #7
What happens if you pass a null date instead?
Nov 16 '05 #8

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

Similar topics

6
by: Gérard Leclercq | last post by:
ACCESS First fields are TEXT, last 2 are Numbers The name of the fields are correct. Dim MyConn Set MyConn=Server.CreateObject("ADODB.Connection") MyConn.Open...
1
by: Paul BJ | last post by:
I am trying to insert into a table in an Access 2000 DB from a VB6 app using ADO 2.7. I would have thought this should have been really easy but I cannot get it working and I cannot see why. It...
17
by: kosta | last post by:
hello! one of my forms communicates with a database, and is supposed to add a row to a table using an Insert statement... however, I get a 'oledb - syntax error' exception... I have double...
3
by: Neil Zanella | last post by:
Hello, I am trying to execute ADO.NET INSERT statement where one of the fields is coming from a password HTML control. When I access the text with password.Value and print with Response.Write...
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...
1
by: solomon_13000 | last post by:
connection.asp: <% Sub RunQueryString (pSQL,parms) on error resume next Set conn = Server.CreateObject("ADODB.Connection") conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &...
6
by: rn5a | last post by:
During registration, users are supposed to enter the following details: First Name, Last Name, EMail, UserName, Password, Confirm Password, Address, City, State, Country, Zip & Phone Number. I am...
1
by: teddymeu | last post by:
Hi Guys, trying to bulk insert a csv file into my SQL database from an asp.net vb web app/form page that the user uploads, my problem is that im new to all this and although the SQL statement...
10
by: Steve Kelley | last post by:
Hello all. I'm new to this group and I'm working on my first real VB.Net project. I'm having trouble creating and archive of a database. We use an Access database to store results from our...
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
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?
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
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,...

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.