Community discussion forum
String was not recognized as a valid DateTime.
Last post was 20 Nov 2008 at 08:40
-
hi i am using asp.net with c# i get this problem when i try to enter date grater than 12 "String was not recognized as a valid DateTime." i am using sql server 2005. In the table field is in datetime format.In the procedure its is also taking as datetime.and the codes are DateTime dob = Convert.ToDateTime(txtdob.Text.ToString().Trim()); rec.Add("dob", dob); rec is a hash table. and the regional setting short date time :MM/dd/yyyy please help
-
Its becoz u have entered a value greateer than 12 for month
-
so what i have to do changing regional setting to dd/MM/yyyy
-
hi, try this: DateTime DTime = new DateTime(); DTime =Convert.ToDateTime(DateTime.Today.Date.ToShortDateString()); lblDate.Text = string.Format("{0:dd/MM/yyyy}",DTime); Regards, Royal
-
Hashtable rec = new Hashtable(); DateTime dob = Convert.ToDateTime(txtdob.Text.Trim()); rec.Add("dob", dob.ToShortDateString()); why the second line not executing .i have gave a brak point to see the flow ,but after the first line its jump to catch()
-
That is because you have an error at runtime. Read the exception to see what is triggering the fault. Regards Si
-
i am using this code in the submit event not in page load. protected void btnSave_Click(object sender, System.EventArgs e) { try { Hashtable rec = new Hashtable(); if (txtdob.Text.Length != 0) { DateTime dob = Convert.ToDateTime(txtdob.Text.Trim()); rec.Add("dob", dob.ToShortDateString());//execution not goes to this line....it jumps to the catch() } } catch( Exception ex) { lblerror.visible=true; lblerror.text=ex.Message; } } exception is again same: String was not recognized as a valid DateTime.
-
i am using this code in the submit event not in page load.
protected void btnSave_Click(object sender, System.EventArgs e) { try { Hashtable rec = new Hashtable(); if (txtdob.Text.Length != 0) { DateTime dob = Convert.ToDateTime(txtdob.Text.Trim()); rec.Add("dob", dob.ToShortDateString());//execution not goes to this line....it jumps to the catch() } } catch( Exception ex) { lblerror.visible=true; lblerror.text=ex.Message; } } exception is again same: String was not recognized as a valid DateTime. -
i am using this code in the submit event not in page load.
protected void btnSave_Click(object sender, System.EventArgs e)
{
try
{
Hashtable rec = new Hashtable();
if (txtdob.Text.Length != 0)
{
DateTime dob = Convert.ToDateTime(txtdob.Text.Trim());
rec.Add("dob", dob.ToShortDateString());//execution not goes to this line....it jumps to the catch()
}
} catch( Exception ex)
{
lblerror.visible=true;
lblerror.text=ex.Message;
}
}
exception is again same: String was not recognized as a valid DateTime. -
Hi, DateTime dob = Convert.ToDateTime(txtdob.Text.Trim()); What you should do is provide the format that the txtdob has in it. for example, DateTime dob = Convert.ToDateTime(txtdob.text.trim(), 'dd/MM/yyyy')); See if that works Si
-
Compiler Error Message: CS1012: Too many characters in character literal
Line 431: if (txtdob.Text.Length != 0)
Line 432: {
Line 433: DateTime dob = Convert.ToDateTime(txtdob.Text.Trim(),'dd/MM/yyyy');
Line 434: rec.Add("dob", dob);
Line 435: } -
oops, my bad. i used single quotes instead of double. Si
-
Compiler Error Message: CS1502: The best overloaded method match for 'System.Convert.ToDateTime(object, System.IFormatProvider)' has some invalid arguments
Source Error:
Line 431: if (txtdob.Text.Length != 0)
Line 432: {
Line 433: DateTime dob = Convert.ToDateTime(txtdob.Text.Trim(),"dd/MM/yyyy");
Line 434: rec.Add("dob", dob);
Line 435: }
-
did u try string.format() ? Regards, Royal
-
HI, sorry, can you try: DateTime dob = Date.ParseExact(txtdob.Text.Trim(), "dd/MM/yyyy"); You will need to change the format to match the datetime format entered in your textbox. Si
-
yes i have tried in string format ,the database is in datetime format,its give the error " Error converting data type nvarchar to datetime."
-
Compiler Error Message: CS1501: No overload for method 'ParseExact' takes '2' arguments
Source Error:
Line 431: if (txtdob.Text.Length != 0)
Line 432: {
Line 433: DateTime dob = DateTime.ParseExact(txtdob.Text.Trim(),"dd/MM/yyyy");
Line 434: rec.Add("dob", dob);
Line 435: } -
hi, did you try this: DateTime DTime = new DateTime(); DTime =Convert.ToDateTime(DateTime.Today.Date.ToShortDateString()); lblDate.Text = string.Format("{0:dd/MM/yyyy}",DTime); Here, firstly I have converted the string into datetime format then I have changed the format of the date to dd/mm/yyyy. Regards, Royal
-
i have used this one but getting the same problem
Hashtable rec = new Hashtable();
if (txtdob.Text.Length != 0)
{
DateTime dob = Convert.ToDateTime(txtdob.Text.Trim());
rec.Add("dob", dob.ToShortDateString());
}
is there any problem with my web server? -
hi, Just now I tried running this: DateTime DT = new DateTime(); DT = Convert.ToDateTime(TextBox1.Text.Trim()); TextBox2.Text = Convert.ToString(string.Format("{0:dd/MM/yyyy}", DT)); and this worked fine. Regards, Royal
-
Its better u add a validator to validate the date before updating the date in the table
-
if (txtdob.Text.Length != 0)
{
DateTime dob = new DateTime();
dob=Convert.ToDateTime(txtdob.Text.Trim());
rec.Add("dob", Convert.ToString(string.Format("{0:dd/MM/yyyy}", dob)));
}
Errot:::String was not recognized as a valid DateTime. -
Validate the textbox using compare validator before u insert it into the table. For eg:
Post a reply
Related discussion
-
Developer Fusion v2 - Announcement
by James Crowley (15 replies)
-
DISABLING/HIDING THE CLOSE BUTTON!?
by Slicksim (19 replies)
-
Chart insertation in a windows form...
by pdhanik (1 replies)
-
Writing Plugin-Based Applications
by haneen (12 replies)
-
ASP .NET Web Service Error Message ,"Client found response content type of 'text/html; charset=utf-8', but expected 'text/xml'."
by salil15august (1 replies)
Related articles
Quick links
Recent activity
- Van Thieu replied to C++ CATMULL-ROM
- Mark Neal replied to Which Blu-ray should i choose?
- emma limei replied to How to Download and Play Yo...
- jump tracy replied to How to transfer or copy so...
- Mark Neal replied to Pavtube Blu-ray Ripper for ...
- tt zhao replied to Which Blu-ray should i choose?
Enter your message below
Sign in or Join us (it's free).