Number of query values and destination fields are not the same

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • roy191991
    New Member
    • Jul 2013
    • 1

    #1

    Number of query values and destination fields are not the same

    Code:
    If str = "add" Then
                ''''''ADD NEW RECORD'''''''
                If txtID.Text = "" Or txtFirst.Text = "" Or txtLast.Text = "" Or txtAddress.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or TextBox5.Text = "" Or TextBox6.Text = "" Or TextBox7.Text = "" Or TextBox8.Text = "" Or TextBox9.Text = "" Or TextBox10.Text = "" Or TextBox11.Text = "" Or TextBox12.Text = "" Or TextBox13.Text = "" Or TextBox14.Text = "" Or TextBox15.Text = "" Or TextBox16.Text = "" Then
    
                    MessageBox.Show("All fields Are Required", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Else
                    myqry = "INSERT INTO  main (ML,DEVICE,LOT,QTY,GATING,DATE1,PKGTYP,DEVICE_NO,LOT_NO,SHELF,ACTUAL_P,E_RETURN,S_RETURN,VARIANCE,VARIANCE_REC,PULLEDBY,RETURN_TD,PROCESSBY,LOCATED,REASON) "
                    myqry = myqry + " VALUES('" & txtID.Text & "','" & txtFirst.Text & "','" & txtLast.Text & "','" & txtAddress.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "','" & TextBox7.Text & "','" & TextBox8.Text & "','" & TextBox9.Text & "','" & TextBox10.Text & "','" & TextBox11.Text & "','" & TextBox12.Text & "','" & TextBox13.Text & "','" & TextBox14.Text & "','" & TextBox15.Text & "','" & TextBox16.Text & "')"
                    mycmd = New OleDbCommand
                    With mycmd
                        .CommandText = myqry
                        .Connection = conn
                        .ExecuteNonQuery()
                    End With
                    Call Set1()
                End If
    Last edited by Rabbit; Jul 24 '13, 03:29 PM. Reason: Please use code tags when posting code or formatted data.
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Actually, this is an easy one. The error message (for once) tells you exactly what's wrong.

    In your SQL INSERT statement, you have provided 19 values to be placed in 20 fields.

    Comment

    Working...