Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
the below statement shows
C#
p1 = new SqlParameter("@empenddate", SqlDbType.Date);
      //p1.Value = DateTime.Parse(txtenddate.Text);
       p1.Value = Convert.ToDateTime(txtenddate.Text);//error
       cmd.Parameters.Add(p1);
Posted
Comments
Zoltán Zörgő 2-Jan-13 9:11am    
And what exactly was in txtenddate.Text at that time? And what is the locale of the system that runs the code?

1 solution

Instead of using the Convert class, I'd suggest using DateTime.Parse[^] wrapped in a try..catch block.

While the error may still remain since it's dependent on the input, this would give you more information about the problem.

Also a good practice is to validate the input first. You can use for example TryParse[^] to test if the input is convertible to datetime.
 
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