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

            myConnection = New SqlConnection(connectionstring)
                myConnection.Open()

                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)
                insert.ExecuteNonQuery()
                insert.Cancel()
                MessageBox.Show("New Project  detail is Added")
                myConnection.Close()

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 for Rahul47

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

Debug.WriteLine(SqlCommand.CommandText)

and post the results here.

Reverend-Jim
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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.