Home > Blockchain >  'No value given for one or more required parameters.' Is there an error in specification o
'No value given for one or more required parameters.' Is there an error in specification o

Time:10-07

Im trying to add data from vb.net textbox to access i cant fix the error. Is it because of data types of radio button, combo box, date time picker?


 Dim count = Convert.ToInt32(cmd.ExecuteScalar())


        If count > 0 Then
            MessageBox.Show("Details already exist")
            con.Close()

        Else
            Dim create As New OleDbCommand("INSERT INTO Household ([lastname] , [firstname] , [middlename] , [extname] , [sex]  ,  [birthdate] , [citizenship] , [birthplace] , [civilstatus] , [occupation] ,
            [housenumber] , [street] , [purok] ) VALUES (@lastname, @firstname , @middlename , @extname , @sex , @birthdate , @citizenship, @birthplace , @civilstatus , @occupation , @housenumber , @street , @purok)", con)


            create.Parameters.AddWithValue("@lastname", OleDb.OleDbType.VarChar).Value = TextBox5.Text.Trim
            create.Parameters.AddWithValue("@firstname", OleDb.OleDbType.VarChar).Value = TextBox6.Text.Trim
            create.Parameters.AddWithValue("@middlename", OleDb.OleDbType.VarChar).Value = TextBox7.Text.Trim
            create.Parameters.AddWithValue("@extname", OleDb.OleDbType.VarChar).Value = TextBox8.Text.Trim
            create.Parameters.AddWithValue("@sex", OleDb.OleDbType.Char).Value = RadioButton1.Checked Or RadioButton2.Checked
            create.Parameters.AddWithValue("@birthdate", OleDb.OleDbType.Date).Value = DateTimePicker1.Value
            create.Parameters.AddWithValue("@citizenship", OleDb.OleDbType.VarChar).Value = TextBox10.Text.Trim
            create.Parameters.AddWithValue("@birthplace", OleDb.OleDbType.VarChar).Value = TextBox9.Text.Trim
            create.Parameters.AddWithValue("@civilstatus", OleDb.OleDbType.Char).Value = ComboBox1.SelectedValue
            create.Parameters.AddWithValue("@occupation", OleDb.OleDbType.VarChar).Value = TextBox11.Text.Trim
            create.Parameters.AddWithValue("@housenumber", OleDb.OleDbType.Numeric).Value = TextBox12.Text.Trim
            create.Parameters.AddWithValue("@street", OleDb.OleDbType.VarChar).Value = TextBox13.Text.Trim
            create.Parameters.AddWithValue("@purok", OleDb.OleDbType.Char).Value = ComboBox2.SelectedValue

[Heres the error][1]


  [1]: https://i.stack.imgur.com/bCXb7.png

CodePudding user response:

I only see one signature for OledbParameterCollection.AddWithValue and it is Public Function AddWithValue (parameterName As String, value As Object) As OleDbParameter https://docs.microsoft.com/en-us/dotnet/api/system.data.oledb.oledbparametercollection.addwithvalue?view=dotnet-plat-ext-5.0

All create.Parameters.AddWithValue should be create.Parameters.Add

To fix the gender problem you need to provide a Char. The lower case c following the string tells the compiler that this is a Char, not a String.

    Dim sex As Char
    If RadioButton1.Checked Then
        sex = "M"c 'Male
    Else
        sex = "F"c 'Female
    End If
    create.Parameters.Add("@sex", OleDb.OleDbType.Char).Value = sex
  • Related