String was not recognized as a valid DateTime.

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2008
Posts: 7
Reputation: pulak2008 is an unknown quantity at this point 
Solved Threads: 0
pulak2008 pulak2008 is offline Offline
Newbie Poster

String was not recognized as a valid DateTime.

 
0
  #1
Nov 19th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 8
Reputation: DoddaLakshman is an unknown quantity at this point 
Solved Threads: 0
DoddaLakshman DoddaLakshman is offline Offline
Newbie Poster

Re: String was not recognized as a valid DateTime.

 
0
  #2
Nov 19th, 2008
hi,

use below way..I think its help you

write
dob.ToShortDateString();

then it will give MM/dd/YYYY formate
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 7
Reputation: pulak2008 is an unknown quantity at this point 
Solved Threads: 0
pulak2008 pulak2008 is offline Offline
Newbie Poster

Re: String was not recognized as a valid DateTime.

 
0
  #3
Nov 19th, 2008
DateTime dob = Convert.ToDateTime(txtdob.Text.ToString().Trim());
rec.Add("dob", dob.ToShortDateString());

same problem arrise ,even execution is not go to the second line.its immidiately jump to catch()
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 8
Reputation: DoddaLakshman is an unknown quantity at this point 
Solved Threads: 0
DoddaLakshman DoddaLakshman is offline Offline
Newbie Poster

Re: String was not recognized as a valid DateTime.

 
0
  #4
Nov 19th, 2008
Hashtable hs = new Hashtable();
DateTime dt = Convert.ToDateTime(TextBox2.Text);
hs.Add("lakshman", dt.ToShortDateString());

using this above code it is working.....let me know any cooncerns
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 7
Reputation: pulak2008 is an unknown quantity at this point 
Solved Threads: 0
pulak2008 pulak2008 is offline Offline
Newbie Poster

Re: String was not recognized as a valid DateTime.

 
0
  #5
Nov 19th, 2008
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()
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 8
Reputation: DoddaLakshman is an unknown quantity at this point 
Solved Threads: 0
DoddaLakshman DoddaLakshman is offline Offline
Newbie Poster

Re: String was not recognized as a valid DateTime.

 
0
  #6
Nov 19th, 2008
Where you wrote this code?...If you write this code in page load it's not work....Why because when you run the application first it runs the page load....that time we haven't give any value to text box.....

If you write this code in any other event it will work....check this and let me know.....
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 7
Reputation: pulak2008 is an unknown quantity at this point 
Solved Threads: 0
pulak2008 pulak2008 is offline Offline
Newbie Poster

Re: String was not recognized as a valid DateTime.

 
0
  #7
Nov 19th, 2008
sir 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());
}
}
catch( Exception ex)
{
lblerror.visible=true;
lbl.text=ex.Message;
}
}
}
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 8
Reputation: DoddaLakshman is an unknown quantity at this point 
Solved Threads: 0
DoddaLakshman DoddaLakshman is offline Offline
Newbie Poster

Re: String was not recognized as a valid DateTime.

 
0
  #8
Nov 19th, 2008
are you giving value in txtdob????
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 7
Reputation: pulak2008 is an unknown quantity at this point 
Solved Threads: 0
pulak2008 pulak2008 is offline Offline
Newbie Poster

Re: String was not recognized as a valid DateTime.

 
0
  #9
Nov 19th, 2008
yes 13/11/1983
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 8
Reputation: DoddaLakshman is an unknown quantity at this point 
Solved Threads: 0
DoddaLakshman DoddaLakshman is offline Offline
Newbie Poster

Re: String was not recognized as a valid DateTime.

 
0
  #10
Nov 19th, 2008
IF you write MM/DD/YYYY formate it is not giving any error.....

If you write DD/MM/YYYY formate it is giving error when you convert to datetime....

try this way and let me know
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



Tag cloud for ASP.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC