Solved

String problem with SQL Server

Posted on 2004-09-21
5
709 Views
Last Modified: 2012-06-21
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
Comment
Question by:jjacksn
  • 2
  • 2
5 Comments
 
LVL 5

Assisted Solution

by:tzxie2000
tzxie2000 earned 250 total points
ID: 12115354
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
 
LVL 15

Expert Comment

by:praneetha
ID: 12115394
query = query.Replace("???TIMESTAMP???", "'" + DateTime.Now.ToString("yyyyMMdd") + "'");

after this line what does query contain?

0
 
LVL 5

Author Comment

by:jjacksn
ID: 12115870
exactly "INSERT INTO region_info(prefix, region, last_update) VALUES ('907209', 'Alaska-Juneau', '20040921');"
0
 
LVL 15

Accepted Solution

by:
praneetha earned 250 total points
ID: 12116050
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
 
LVL 5

Author Comment

by:jjacksn
ID: 12116525
nm, it was a different problem.  
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now