I am getting an error when adding parameters to my OleDbCommand. The error is telling me that @Gender has no default value.

SQL = "INSERT INTO MEMBER ( [RFID], [ID], [FULLNAME], [POSITION], [GENDER]," & _
      " [DATEENCODED] )VALUES ( @RFID, @ID, @FULLNAME, @POSITION, @GENDER, @DATEENCODED)"


Dim cmd As New OleDb.OleDbCommand(SQL, conn)
cmd.Parameters.Add(New OleDb.OleDbParameter("@RFID", Form3.txtrfid.Text))
cmd.Parameters.Add(New OleDb.OleDbParameter("@ID", Form3.txtid.Text))
cmd.Parameters.Add(New OleDb.OleDbParameter("@FULLNAME", a))
cmd.Parameters.Add(New OleDb.OleDbParameter("@POSITION", Form3.txtpost.Text))
cmd.Parameters.Add(New OleDb.OleDbParameter("@GENDER", Form3.cbogen.SelectedItem))
cmd.Parameters.Add(New OleDb.OleDbParameter("@DATEENCODED", b))

1 Answers

0
Mary On

At design time set the DropDownStyle property of the combo box to DropDownList Use a data source instead of add items to the collection at design time or Items.Add or Items.AddRange at run time.

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim G() As String = {"Male", "Female", "Other"}
    ComboBox1.DataSource = G
    MessageBox.Show(ComboBox1.SelectedItem.ToString)
End Sub