i got this error i already checked my table definition

Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click

        da.InsertCommand = New SqlCommand("INSERT INTO AdmissionRecord VALUES(@Patient_ID, @Patient_Type, @LName)", cs)

        da.InsertCommand.Parameters.Add("@Patient_ID", SqlDbType.VarChar).Value = Txtpatient_id.Text
        da.InsertCommand.Parameters.Add("@Case_Number", SqlDbType.VarChar).Value = txtCaseNumber.Text

        da.InsertCommand.Parameters.Add("@Patient_Type", SqlDbType.VarChar).Value = IIf(String.IsNullOrEmpty(cboxpatient_Type.Text), DBNull.Value, cboxpatient_Type.Text)
        da.InsertCommand.Parameters.Add("@LName", SqlDbType.VarChar).Value = 

        cs.Open()
        da.InsertCommand.ExecuteNonQuery()

        cs.Close()
        MsgBox("New Patient Successfully admitted!")


        Txtpatient_id.Text = patientID
        txtCaseNumber.Text = caseNUM
        TxtChart_ID.Text = chartID
        cboxpatient_Type.Text = ""
        TxtLName.Text = ""

pls help anybody

When you insert this way, you HAVE to provide a value for every column in the table and it has to be in the proper order to match the table or you might get data conversion errors.

My guess is that the table has more than 3 columns.

You could specify the column names to be inserted into with your SQL statment

EDIT: You are missing "@Case_Number" from your insert SQL

Edited 5 Years Ago by CodeWord: n/a

hi thanks i still got the problem. yes i have more than 3 columns..hmm i placed it in the proper order but why am i still getting the same error? i followed ur advice

Did you notice the missing @Case_Number in your SQL statment? You are setting the parameter, but you have no such parameter in your statement. That's a problem as well.

Here is your code, reworked to include the missing parameter, and to specify fields:

INSERT INTO AdmissionRecord (Patient_ID, Case_Number, Patient_Type, LName) VALUES(@Patient_ID, @Case_Number, @Patient_Type, @LName)

Edit: The cut and paste operation didn't work. So, here is just the SQL statment. Notice, I added the Case_Number. Also, verify the field names are spelled correctly. I went off your parameter names.

Edited 5 Years Ago by CodeWord: n/a

This article has been dead for over six months. Start a new discussion instead.