0

I get an error about datetime,date and time.. i got 3 different datatype , mostly error all of them.. how do i get it right?

this datatype datetime: i dont know sometime i got it worked and some dont..

comu.Parameters.Add("Casedate", SqlDbType.DateTime);
comu.Parameters["Casedate"].Value = Convert.ToDateTime(TextBox1.Text);

this are datatype date only:

comu.Parameters.Add("Startdate", SqlDbType.Date);
comu.Parameters["Startdate"].Value = Convert.ToString(TextBox12.Text);

comu.Parameters.Add("Enddate", SqlDbType.Date);
comu.Parameters["Enddate"].Value = Convert.ToString(TextBox13.Text);

this are datatype time:

comu.Parameters.Add("Starttime", SqlDbType.Time);
comu.Parameters["Starttime"].Value = Convert.ToString(TextBox14.Text);

comu.Parameters.Add("Endtime", SqlDbType.Time);
comu.Parameters["Endtime"].Value = Convert.ToString(TextBox15.Text);

now i have problem on datetime, but in the last page i got it worked by put in data 11/11/2014 data in it... but now it show error on datetime back

2
  • 1
    what is the format that user enters in textbox Commented Apr 21, 2014 at 8:05
  • for datetime should be dd/mm/yyyy hh:mm:ss for time should be hh:mm:ss for date should be dd/mm/yyyy @SudhakarTillapudi Commented Apr 21, 2014 at 8:10

2 Answers 2

2

if you know the DateTime format upfront you can use DateTime.ParseExact() method to parse the given date time value properly

using System.Globalization;

DateTime dt = DateTime.ParseExact(datestring, "dd/MM/yyyy 
                                  hh:mm:ss",CultureInfo.InvariantCulture);
Sign up to request clarification or add additional context in comments.

2 Comments

im sorry , this are too advance for me.. idk how DateTime dt = DateTime.ParseExact(datestring, "dd/MM/yyyy hh:mm:ss",CultureInfo.InvariantCulture); goes?
it parses the DateTime object from the given datetime format exactly.please check this link for more info msdn.microsoft.com/en-us/library/w2sa9yss(v=vs.110).aspx
1

You should use the DateTime.Parse() method, you are converting a string to a string.

DateTime.Parse(TextBox1.Text)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.