• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 729
  • Last Modified:

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.
0
jjacksn
Asked:
jjacksn
  • 2
  • 2
2 Solutions
 
tzxie2000Commented:
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
 
praneethaCommented:
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
 
jjacksnAuthor Commented:
nm, it was a different problem.  
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now