Insert string into database

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi

SQL queries does not recognize *$()!.,?/\[]{};:'"&^+=<>|.

if I have a variable alike this:
Date = "Thursday, March 01, 2007 - 9:53 PM";

how can I inset in my database?

strCommand = "INSERT INTO Profiles (Date) " +
"VALUES ('" + Date + "')";

..............................................

thisCommand.ExecuteNonQuery();

Thank you;
Monica.
 
Hi Monica,
Dates are a bit tricky.
The following are just general ideas to help you get closer to a solution

1) Try DateTime.TryParse(Yourdatestring, out tempdatevariable)
Your date string does not parse on my machine.
So your string is not compatible with my regional settings
Change the date string "2007-03-01 21:53:00" and it does.
By providing the Date.TryParse with an appropriate IFormatter you may be
able transform your string into a valid DateTime variable. Once you are
there you should be able to use one of the datetime variable
tosomethingstring methods to get a string that will work for you.


2)Have you access to SQLAnalyser? if so put in a manual insert command using
your 'Date' and see what happens.
3) I would have thought the format with the best chance of success would be
yyyy-mm-dd hh:mm:ss, again a play with SQL Analyser might save you some
time.
4) So may be you can unpack your date string and re-arrange it manually to a
suitable format.
HTH
Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top