Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-Server-2008
the below statement shows
p1 = new SqlParameter("@empenddate", SqlDbType.Date);
      //p1.Value = DateTime.Parse(txtenddate.Text);
       p1.Value = Convert.ToDateTime(txtenddate.Text);//error
       cmd.Parameters.Add(p1);
Posted 2-Jan-13 3:09am
Comments
Zoltán Zörgő at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Shai Vashdi 1,518
1 Tadit Dash 350
2 Manas Bhardwaj 319
3 OriginalGriff 243
4 Sergey Alexandrovich Kryukov 205
0 Sergey Alexandrovich Kryukov 9,530
1 OriginalGriff 5,716
2 Peter Leow 4,320
3 Maciej Los 3,540
4 Abhinav S 3,373


Advertise | Privacy | Mobile
Web01 | 2.8.140415.2 | Last Updated 2 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid