Click here to Skip to main content
12,948,567 members (61,814 online)
Rate this:
Please Sign up or sign in to vote.
the below statement shows
p1 = new SqlParameter("@empenddate", SqlDbType.Date);
      //p1.Value = DateTime.Parse(txtenddate.Text);
       p1.Value = Convert.ToDateTime(txtenddate.Text);//error
Posted 2-Jan-13 3:09am
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

Rate this: bad
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.

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 5,419
CHill60 3,275
Maciej Los 2,778
Jochen Arndt 1,935
ppolymorphe 1,795

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100