473,735 Members | 7,561 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6670
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.co m

"kosta" <an*******@disc ussions.microso ft.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*******@disc ussions.microso ft.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.ConnectionS tring =
ConfigurationSe ttings.AppSetti ngs["conString"];
OleDbCommand cmd = new OleDbCommand(sq l,con);
con.Open();
cmd.ExecuteNonQ uery();
string identity = "select @@identity";
cmd.CommandText = identity;
int id = (int)cmd.Execut eScalar();
con.Close();
return id;
}

and the exception:
{"Syntax error in INSERT INTO statement."}
[System.Data.Ole Db.OleDbExcepti on]: {"Syntax error in
INSERT INTO statement."}
Data: {System.Collect ions.ListDictio naryInternal}
HelpLink: null
InnerException: null
Message: "Syntax error in INSERT INTO statement."
Source: "Microsoft JET Database Engine"
StackTrace: " at
System.Data.Ole Db.OleDbCommand .ExecuteCommand TextErrorHandli ng(OleDbHResult
hr)\r\n at
System.Data.Ole Db.OleDbCommand .ExecuteCommand TextForSingleRe sult(tagDBPARAM S
dbParams, Object& executeResult)\ r\n at
System.Data.Ole Db.OleDbCommand .ExecuteCommand Text(Object&
executeResult)\ r\n at
System.Data.Ole Db.OleDbCommand .ExecuteCommand (CommandBehavio r
behavior, Object& executeResult)\ r\n at
System.Data.Ole Db.OleDbCommand .ExecuteReaderI nternal(Command Behavior
behavior, String method)\r\n at
System.Data.Ole Db.OleDbCommand .ExecuteNonQuer y()\r\n at
SQL.Connect.ANu m(String sql) in f:\\my documents\\visu al
studio\\project s\\connect\\con nect.cs:line 63\r\n at
SQLStatements.P artiesDB.AddPar tier(Boolean Sex, String
LName, String FName, String CPhone, String Phone, String
City, DateTime BDay, Boolean Car, String PicPath, String
PotentialClient , String PotentialTrippe r, String PCities)
in f:\\my documents\\visu al
studio\\project s\\sqlstatement s\\partiersdb.c s:line 20\r\n
at DataBase.Partye r
Update.Add() in F:\\My Documents\\Visu al
Studio\\Project s\\Database\\Pa rtyerUpdate.cs: line 35"
TargetSite: {Void
ExecuteCommandT extErrorHandlin g(System.Data.O leDb.OleDbHResu lt)}
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.ConnectionS tring =
ConfigurationSe ttings.AppSetti ngs["conString"];
OleDbCommand cmd = new OleDbCommand(sq l,con);
con.Open();
cmd.ExecuteNonQ uery();
string identity = "select @@identity";
cmd.CommandText = identity;
int id = (int)cmd.Execut eScalar();
con.Close();
return id;
}

and the exception:
{"Syntax error in INSERT INTO statement."}
[System.Data.Ole Db.OleDbExcepti on]: {"Syntax error in
INSERT INTO statement."}
Data: {System.Collect ions.ListDictio naryInternal}
HelpLink: null
InnerException: null
Message: "Syntax error in INSERT INTO statement."
Source: "Microsoft JET Database Engine"
StackTrace: " at
System.Data.Ole Db.OleDbCommand .ExecuteCommand TextErrorHandli ng(OleDbHResult
hr)\r\n at
System.Data.Ole Db.OleDbCommand .ExecuteCommand TextForSingleRe sult(tagDBPARAM S
dbParams, Object& executeResult)\ r\n at
System.Data.Ole Db.OleDbCommand .ExecuteCommand Text(Object&
executeResult)\ r\n at
System.Data.Ole Db.OleDbCommand .ExecuteCommand (CommandBehavio r
behavior, Object& executeResult)\ r\n at
System.Data.Ole Db.OleDbCommand .ExecuteReaderI nternal(Command Behavior
behavior, String method)\r\n at
System.Data.Ole Db.OleDbCommand .ExecuteNonQuer y()\r\n at
SQL.Connect.ANu m(String sql) in f:\\my documents\\visu al
studio\\project s\\connect\\con nect.cs:line 63\r\n at
SQLStatements.P artiesDB.AddPar tier(Boolean Sex, String
LName, String FName, String CPhone, String Phone, String
City, DateTime BDay, Boolean Car, String PicPath, String
PotentialClient , String PotentialTrippe r, String PCities)
in f:\\my documents\\visu al
studio\\project s\\sqlstatement s\\partiersdb.c s:line 20\r\n
at DataBase.Partye r
Update.Add() in F:\\My Documents\\Visu al
Studio\\Project s\\Database\\Pa rtyerUpdate.cs: line 35"
TargetSite: {Void
ExecuteCommandT extErrorHandlin g(System.Data.O leDb.OleDbHResu lt)}
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.ConnectionS tring =
ConfigurationSe ttings.AppSetti ngs["conString"];
OleDbCommand cmd = new OleDbCommand(sq l,con);
con.Open();
cmd.ExecuteNonQ uery();
string identity = "select @@identity";
cmd.CommandText = identity;
int id = (int)cmd.Execut eScalar();
con.Close();
return id;
}

and the exception:
{"Syntax error in INSERT INTO statement."}
[System.Data.Ole Db.OleDbExcepti on]: {"Syntax error in
INSERT INTO statement."}
Data: {System.Collect ions.ListDictio naryInternal}
HelpLink: null
InnerException: null
Message: "Syntax error in INSERT INTO statement."
Source: "Microsoft JET Database Engine"
StackTrace: " at
System.Data.Ole Db.OleDbCommand .ExecuteCommand TextErrorHandli ng(OleDbHResult
hr)\r\n at
System.Data.Ole Db.OleDbCommand .ExecuteCommand TextForSingleRe sult(tagDBPARAM S
dbParams, Object& executeResult)\ r\n at
System.Data.Ole Db.OleDbCommand .ExecuteCommand Text(Object&
executeResult)\ r\n at
System.Data.Ole Db.OleDbCommand .ExecuteCommand (CommandBehavio r
behavior, Object& executeResult)\ r\n at
System.Data.Ole Db.OleDbCommand .ExecuteReaderI nternal(Command Behavior
behavior, String method)\r\n at
System.Data.Ole Db.OleDbCommand .ExecuteNonQuer y()\r\n at
SQL.Connect.ANu m(String sql) in f:\\my documents\\visu al
studio\\project s\\connect\\con nect.cs:line 63\r\n at
SQLStatements.P artiesDB.AddPar tier(Boolean Sex, String
LName, String FName, String CPhone, String Phone, String
City, DateTime BDay, Boolean Car, String PicPath, String
PotentialClient , String PotentialTrippe r, String PCities)
in f:\\my documents\\visu al
studio\\project s\\sqlstatement s\\partiersdb.c s:line 20\r\n
at DataBase.Partye r
Update.Add() in F:\\My Documents\\Visu al
Studio\\Project s\\Database\\Pa rtyerUpdate.cs: line 35"
TargetSite: {Void
ExecuteCommandT extErrorHandlin g(System.Data.O leDb.OleDbHResu lt)}
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.co m

"kosta" <an*******@disc ussions.microso ft.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
2214
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 "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath ("/xdata/sc.mdb")
1
2659
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 is years and years since I did anything with Access so I am wondering what I have forgotten... I am sending a SQL string as follows directly from a connection object using Connection.Execute(strSQL) and I get an incorrect synatax error.
17
683
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 checked, and the insert works fine (tried to use it from access)... im using visual C# express 2k5... what could be wrong? thanks! it is an access 2000 database. here is the statement:
3
2821
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 so as to check that it is working correctly it displays just fine. However, whenever I include the password field in one of the SQL INSERT statement's fields I get the following error:
3
2310
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 example I had to go by 'INSERT INTO tblCustomers (CustomerID, , )
1
5034
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=" & Server.MapPath("/db/VideoBlog.mdb") & ";" Set cmd = Server.CreateObject("ADODB.command") With cmd
6
3467
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 using MS-Access 2000 database table for this app. Note that the datatype of all the fields mentioned above are Text. Apart from the above columns, there's another column in the DB table named 'RegDateTime' whose datatype is Date/Time which is...
1
3097
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 inserts the CSV within my SQL Query analyser it comes up with this error in the actual app when trying to run it, ive probably done this wrong so can someone look at the error and my code and point me in the right direction Server Error in...
10
1640
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 instruments and need to give our customers the ability to archive their results and prune the archived data from the main database. This query string works in .Net with the connection string defined to point to the parent database. "insert into...
0
8962
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9327
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9251
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9200
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6049
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4559
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4822
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3273
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2739
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.