Dim startdate1 As String = DateTimePicker1.Value.Date
            Dim enddate As String = DateTimePicker2.Value.Date

            myConnection = New SqlConnection(connectionstring)

                Dim insert As SqlCommand = New SqlCommand(" INSERT INTO Client_Details (Contract_Name ,Client_Name  ,VAT_No ,Cilent_Address,Start_Date,End_Date ,Contract_Value,Telephone_No) VALUES('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox3.Text & "','" & startdate1 & "','" & enddate & "','" & TextBox7.Text & "')", myConnection)
                MessageBox.Show("New Project  detail is Added")

when use this coding to insert a date value I got the error below.
"conversion failed when converting datetime from string"
I used sql 2005 & vb.net 2008

Member Avatar

Try this directly into your query:

Substitute DateValue(DateTimePicker1.Value.Date) in place of startdate1 in SQL Query, and DateValue(DateTimePicker2.Value.Date) in place of enddate.

You can't tell what's wrong with a query unless you can see the query. After you create it do


and post the results here.

Can you what is going happen I used your coding

Plz show your Table .... What data Type there Of start_date

your problem is with DataType in Backend Table what dataType u used for start_date and End_date.