String problem with SQL Server

I have a string problem with SQL server, I have code that dynamically generates SQL commands from XML data, one of which is:



query = query.Replace("???TIMESTAMP???", "'" + DateTime.Now.ToString("yyyyMMdd") + "'");

{"ERROR [07002] [Microsoft][ODBC SQL Server Driver]COUNT field incorrect or syntax error" }      System.Exception

INSERT INTO region_info(prefix, region, last_update) VALUES ('907209', 'Alaska-Juneau', '20040921');

Now, the replace is creating the query of the above line.  When I cut and paste that line from the exception text into the Query Analyazer, it runs fine.  I'm misisng my problem somewhere.
LVL 5
jjacksnAsked:
Who is Participating?
 
praneethaConnect With a Mentor Commented:
hardcode query="INSERT INTO region_info(prefix, region, last_update) VALUES ('907209', 'Alaska-Juneau', '20040921');"

and see if that works

is " at the start and end part of query-

i mean is query=" "insert into.... " "
0
 
tzxie2000Connect With a Mentor Commented:
could you show a little more code about it?

I think it may be the different of acceptable datetime between Query Analyazer and C#
0
 
praneethaCommented:
query = query.Replace("???TIMESTAMP???", "'" + DateTime.Now.ToString("yyyyMMdd") + "'");

after this line what does query contain?

0
 
jjacksnAuthor Commented:
exactly "INSERT INTO region_info(prefix, region, last_update) VALUES ('907209', 'Alaska-Juneau', '20040921');"
0
 
jjacksnAuthor Commented:
nm, it was a different problem.  
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.