Click here to Skip to main content
15,906,645 members

Comments by Member 14969139 (Top 2 by date)

Member 14969139 20-Oct-20 5:22am View    
The complete code for the Button Click is listed below. It errors at ADAPTER.InsertCommand.ExecuteNonQuery()


myConn = New SqlConnection("Data Source = CSA10;Initial Catalog=TaskManager;Integrated Security=SSPI")
myConn.Open()
myCmd = myConn.CreateCommand
myCmd.CommandText = "INSERT INTO TASKMANAGER.dbo.CONSULTANT (ID,NAME,RMCVALIDITY) VALUES ('2','" & TextBox1.Text & "','" & DateTimePicker2.Value.Date & "')"
'myCmd.CommandText = "INSERT INTO TASKMANAGER.dbo.CONSULTANT (ID,NAME,DEPARTMENT,DEPARTMENT2,DESIGNATION,RMCNO,RMCVALIDITY,INDEMNITYVALIDITY,DOB,REMARKS) VALUES ('2','" & TextBox1.Text & "','MEDICAL','" & ComboBox1.Text & "','" & ComboBox3.Text & "','" & TextBox2.Text & "','CAST(" & DateTimePicker2.Value & "AS DATE)','CAST(" & DateTimePicker3.Value & "AS DATE)','CAST(" & DateTimePicker1.Value & "AS DATE)','" & TextBox3.Text & "')"
Dim ADAPTER As New SqlDataAdapter(myCmd)
ADAPTER.InsertCommand = New SqlCommand(myCmd.CommandText, myConn)
ADAPTER.InsertCommand.ExecuteNonQuery()
myCmd.Dispose()
myConn.Close()
Member 14969139 20-Oct-20 5:02am View    
Hi I am using VB. Confused about the code above. Listed below is my code.

myCmd.CommandText = "INSERT INTO TASKMANAGER.dbo.CONSULTANT (ID,NAME,RMCVALIDITY) VALUES ('2','" & TextBox1.Text & "','" & Me.DateTimePicker2.Value & "')"

Error message I get is 'System.Data.SqlClient.SqlException: 'Conversion failed when converting date and/or time from character string.'