472,961 Members | 1,761 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,961 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 6589
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
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.