MS Access Database error: No value given for one or more required parameters

Last Reply on Nov 26, 2014 01:52 AM By Azim

Posted on Nov 24, 2014 01:47 AM

in my asp.net+vb web i am using this code to bind data. it works fine.

 

 Protected Sub DropDownList3_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList3.SelectedIndexChanged
        If DropDownList3.Text = "Please Select" Then
            Page.ClientScript.RegisterStartupScript(Me.GetType, "Forms", "<script> alert('Please select a valid ID1 ... it can't be blank.........') </script>")
            DropDownList3.Focus()
            Exit Sub
        End If
        Dim connectString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                                                          "Data Source=C:\web\baiju.mdb"
        Dim con As OleDbConnection = New OleDbConnection(connectString)
        con.Open()
        Dim qstr As String
        qstr = "select * from Tak1 where id1=" + DropDownList3.Text + ";"
        Dim OleDb As New OleDbDataAdapter(qstr, con)
        Dim dt As New DataSet
        OleDb.Fill(dt, "[Tak1]")
        If dt.Tables("[Tak1]") IsNot Nothing AndAlso dt.Tables("[Tak1]").Rows.Count > 0 AndAlso (dt.Tables("[Tak1]").Rows(0).Item("Remarks_") Is System.DBNull.Value <> True) Then
            addlrmk.Text = dt.Tables("[Tak1]").Rows(0).Item("Remarks_")
        Else
            addlrmk.Text = ""
        End If
End Sub

i have alrady added this code.

If DropDownList3.Text = "Please Select" Then
            Page.ClientScript.RegisterStartupScript(Me.GetType, "Forms", "<script> alert('Please select a valid ID1 ... it can't be blank.........') </script>")
            DropDownList3.Focus()
            Exit Sub
        End If

still it gives eror as

No value given for one or more required parameters.

Posted on Nov 26, 2014 01:52 AM

Please use this code it uses Parameters to pass value to the Query.

Protected Sub DropDownList3_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList3.SelectedIndexChanged
    If DropDownList3.SelectedItem.Value = "Please Select" Then
        Page.ClientScript.RegisterStartupScript(Me.GetType, "Forms", "<script> alert('Please select a valid ID1 ... it can't be blank.........') </script>")
        DropDownList3.Focus()
    Else
        Dim connectString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                                                          "Data Source=C:\web\baiju.mdb"
        Dim con As OleDbConnection = New OleDbConnection(connectString)
        con.Open()
        Dim qstr As String
        qstr = "select * from Tak1 where id1 = @id1"
        Dim OleDb As New OleDbDataAdapter(qstr, con)
        OleDb.SelectCommand.Parameters.AddWithValue("@id1", DropDownList3.SelectedItem.Value)

        Dim dt As New DataSet
        OleDb.Fill(dt, "[Tak1]")
        If dt.Tables("[Tak1]") IsNot Nothing AndAlso dt.Tables("[Tak1]").Rows.Count > 0 AndAlso (dt.Tables("[Tak1]").Rows(0).Item("Remarks_") Is System.DBNull.Value <> True) Then
            addlrmk.Text = dt.Tables("[Tak1]").Rows(0).Item("Remarks_")
        Else
            addlrmk.Text = ""
        End If
    End If
End Sub

 

I agree, here is the link: https://www.e-iceblue.com/Introduce/spire-office-for-net-free.html