Could you please post the sql statement. Which is the db you are using - is
it access?
Regards,
Rakesh Rajan
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]
- m...@spam.guard.caspershouse.com
"kosta" <anon...@discussions.microsoft.com> wrote in message
news:0b5301c4b2dd$cedfb360$a301...@phx.gbl...
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.ExecuteCommandTextErrorHandling(OleDbHResult
hr)\r\n at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS
dbParams, Object& executeResult)\r\n at
System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object&
executeResult)\r\n at
System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior
behavior, Object& executeResult)\r\n at
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(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:line 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.
>.
>
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" <anon...@discussions.microsoft.com> wrote in message
news:0b5301c4b2dd$cedfb360$a301...@phx.gbl...
and the exception:
>.
>
and the exception:
>Message unavailable
and the exception:
Kosta.
And whether or not it turns out that that's the problem, embedding
values directly into SQL like that isn't generally a good idea. Use
parameters (in this case OleDbParameter) instead, so that the driver
does any formatting required.
--
Jon Skeet - <sk...@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
This is about finding an error. I am not suggesting that using hard-coded
values is a better solution. By not seeing the values being passed we cannot
say that no mismatch is taking place. So I would like to see values (or
actually, have kosta make sure that there is no mismatch ;-) ), reduced
statements and the like.
as for the OleDbParameter, could you please elaborate a
bit? Im kinda doing what ive been taught... cwhy is my way
wrong/not a good idea? what adventeges does oledbparameter
has over my way? and how is it used?
thanks!
kosta
>.
>
If you haven't tried, you just don't know. If you can't see anything
wrong, but people have suggested a way of testing something, why not
test it?
> as for the OleDbParameter, could you please elaborate a
> bit? Im kinda doing what ive been taught... cwhy is my way
> wrong/not a good idea? what adventeges does oledbparameter
> has over my way? and how is it used?
See http://www.pobox.com/~skeet/csharp/faq/#db.parameters
If you've been taught to embed values in SQL statements, btw, I would
have a very close look at what else you've been taught from the same
source.
you gave this SQL 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, '', '', '', '')
I would first
- remove the columns/values that are not mandatory
- add the column names of the remaining columns
- test the effects of the above and try to pass a null date as well if
possible
Then post the remaining statement and the test result. Maybe even post the
table definition.
Maybe the problem has another origin but that is not something that I can
see with the information you provided sofar. So my suggestion is to
eliminate possible causes.
For instance, the values for columns - Sex, Last, First should be passed
to the command object as parameter objects as follows
cmd.Parameters.Add(new OleDbParameter("@Sex"));
cmd.Parameter["@Sex"].Value='';
etc.
with regards,
J.V.Ravichandran
- http://www.geocities.com/
jvravichandran
- http://www.411asp.net/func/search?
qry=Ravichandran+J.V.&cob=aspnetpro
- http://www.southasianoutlook.com
- http://www.MSDNAA.Net
- http://www.csharphelp.com
- http://www.poetry.com/Publications/
display.asp?ID=P3966388&BN=999&PN=2
- Or, just search on "J.V.Ravichandran"
at http://www.Google.com
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Ron Allen
"kosta" <anon...@discussions.microsoft.com> wrote in message
news:158201c4b43f$dbf54480$a401...@phx.gbl...
Best Regards,
Kosta.
wow, ive been posting from msdn... now i looked at it from google
groups since it finally worked, and I see that i maw maybe half of the
messages posted...
thanks to everyone who posted! I will try all of these!
Then you'd be doing the students who come after you a favour if you
dropped your teachers an email to ask them to teach their students to
use parameters rather than inserting values directly into SQL
statements. It can help performance, security and correctness.