This is my code that will insert data into a datagridview first then into database.
When I run the code, I get the error
operand type clash bit is incompatible with date
Can anyone help me?
Thanks in advance
populate(txtRejectID.Text, comboBoxCardType.Text, txtEmbossName.Text, txt6CardNum.Text, txt4CardNum.Text, txtQuantity.Text, comboBoxErrorDesc.Text, embossDate.Text, txtStatus.Text)
For Each row As DataGridViewRow In DataGridView1.Rows
Dim query As String = "INSERT INTO dbo.RejectCard VALUES (@RejectID, @Card_Type, @Emboss_Name, @Card_Number, @Quantity, @Error_Description, @Emboss_Date, @Status)"
Using conn As New SqlConnection(connString)
Using cmd As New SqlCommand(query, conn)
cmd.Parameters.AddWithValue("@RejectID", row.Cells("rejectid").Value)
cmd.Parameters.AddWithValue("@Card_Type", row.Cells("cardtype").Value)
cmd.Parameters.AddWithValue("@Emboss_Name", row.Cells("embossname").Value)
cmd.Parameters.AddWithValue("@Card_Number", row.Cells("cardnumber").Value)
cmd.Parameters.AddWithValue("@Quantity", row.Cells("quantity").Value)
cmd.Parameters.AddWithValue("@Error_Description", row.Cells("errordescription").Value)
cmd.Parameters.AddWithValue("@Emboss_Date", row.Cells("emboss_Date").Value = embossDate.Value.Date.ToString("dd/MM/yyyy"))
cmd.Parameters.AddWithValue("@Status", row.Cells("status").Value)
Try
conn.Open()
cmd.Connection = conn
cmd.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show("Error while inserting record on table..." & ex.Message, "Insert Records")
Finally
conn.Close()
End Try
End Using
End Using
Next
MessageBox.Show("Records inserted.")
End Sub
ExecuteNonQuerythen you should be creating one connection and one command, adding all the paremeters, opening the connection and THEN starting the loop. In the loop, you set theValueof each parameter and call then execute. Even better, just create aDataTableand bind it to the grid, then save the lot with oneUpdatecall.