Click here to Skip to main content
15,905,144 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI there, i want to update the date value in my db table. it is a type date field.
In my form I use a datetime picker called dtpRecallDate for choosing the date and another one called dtpRecallTime for choosing the time.
The code i am using is the following:

C#
DateTime dtime;
string RecallDateTime = "";

if (dtpRecallDate.Value.ToString() != "" && dtpRecallTime.Value.ToString() != "")
{
    RecallDateTime = (dtpRecallDate.Value.ToString("s") + " " + dtpRecallTime.Value.ToString("s"));

}
DateTime.TryParse(RecallDateTime, out dtime);
MerchantData1["RecallDate"] = dtime.ToString();
DataConnection.UpdateRow("MerchantCalls", MerchantData1, " WHERE  MerchantCallID = " + _merchcallid + " ");


When i press the enter button i get the following message:

"syntax error converting datetime from character string"

I know it's probably something very simple but i have already waisted one hour trying to solve it!!!
Any help will be much appreciated.
Thnx in advance!
Posted
Updated 10-Feb-12 3:15am
v2

Read your code. Use the debugger to step through it. Learn how to use your tools.

RecallDateTime is "" if the two values are the same. Otherwise, it's two dates joined together. It's never one date, so parsing will never work. Also, when you call tryparse, it returns true or false, if you ignore that return value, you're writing bad code. The system told you it could not parse the string and you ignored it.
 
Share this answer
 
Comments
MCY 11-Feb-12 15:11pm    
yeah, good points
If you use breakpoint and check the following code here,
C#
RecallDateTime = (dtpRecallDate.Value.ToString("s") + " " + dtpRecallTime.Value.ToString("s"));

RecallDateTime will have value of say 9 9 when the time is 9 seconds. or say
23 59 when seconds in dtpRecallDate is 23 seconds, and time in dtpRecallTime is 59 seconds.

This is not a valid datetime format.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900