Conversion failed when converting date and/or time from character string. [Resolved]

Posted by Cibin under ASP.NET on 6/9/2013 | Points: 10 | Views : 32676 | Status : [Member] | Replies : 4
Dear Sir/Madam,,

sql = "insert into msgdetails values(" & Val(TextBox1.Text) & ",'" & TextBox2.Text & "','" & TextBox6.Text & "','" & TextBox5.Text & "','" & TextBox3.Text & "','" & TextBox7.Text & "','" & Label11.Text & "'," & DateValue(Label3.Text) & ",'" & Label5.Text & "','" & DropDownList1.Text & "','" & TextBox4.Text & "')"

This my Code , I can't see any error in this , But wen i run the code it shows an Error "Conversion failed when converting date and/or time from character string." .
Please Help me out.

In Database , The type of field date1 as Date,, Here label3 shows the current date using the code : Label3.Text = System.DateTime.Now.ToShortDateString()

Wat will i Do?

Thanks in Advance...




Responses

Posted by: Raj.Trivedi on: 6/9/2013 [Member] [MVP] Starter | Points: 50

Up
0
Down

Resolved
Hello try this

label3.text = System.DateTime.Now.ToString();

keep the datatype as datetime

Regard's
Raj.Trivedi
"Sharing is Caring"
Please mark as answer if your Query is resolved

Cibin, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raj.Trivedi on: 6/9/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hello Cibin

Try Changing the datatype of the field as datetime instead of date..

Regard's
Raj.Trivedi
"Sharing is Caring"
Please mark as answer if your Query is resolved

Cibin, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Cibin on: 6/9/2013 [Member] Starter | Points: 25

Up
0
Down

i Changed the datatype ,, But i getting the same error

Cibin, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Cibin on: 6/9/2013 [Member] Starter | Points: 25

Up
0
Down
Thanks Raj,

I Got the answer, The mistake is ,, one of the value is placed not in exact position,. Anyway Thanks for ur help.

Cibin, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response