No Value given for one or more required parameters in Vb6

Viewed 97

I'm new to Vb6.

I haven't inserted data in my database and when I run the program, an error shows No Value given for one or more required parameters

Here's the code:

Dim list As ListItem, r As Integer
If recset.State = adStateOpen Then recset.Close

recset.Open "SELECT StudentId, LastName, FirstName, MiddleName FROM Students ORDER BY StudentId", rainCon, adOpenStatic, adLockOptimistic

If recset.RecordCount > 1 Then
    MsgBox "No Data Found!", vbInformation, ""
Else
    ListView1.ListItems.Clear
    Do While Not recset.EOF
    
        r = r + 1
        
        Set list = ListView1.ListItems.Add(, , r)
        list.SubItems(1) = recset(0).Value
        list.SubItems(2) = recset(1).Value
        list.SubItems(3) = recset(2).Value
        list.SubItems(4) = recset(3).Value
    
        recset.MoveNext
    Loop
End If

Then highlights recset.Open part. How to control or fix this error?

2 Answers

When I tried to re-check my code and database multiple times. I found out that there was a missing attribute in my students table. The code was fully functional.

Find out the full working code.

Private Sub cmdAddItemtoListBox_Click()

'Enter Code here....

End Sub

Change database path, name, and table as per your data.

Output Screenshot

Dim xCon    As New ADODB.Connection

Dim rsTable As New ADODB.Recordset

Dim StrSqlQuery As String

Dim Counter     As Integer

Dim list        As ListItem

If xCon.State = 1 Then xCon.Close
xCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Test\Test.mdb;Persist Security Info=False"
'
StrSqlQuery = ""
StrSqlQuery = "Select * from Data Order by PrintSl"

If rsTable.State = 1 Then rsTable.Close
rsTable.CursorLocation = adUseClient
rsTable.Open StrSqlQuery, xCon, adOpenStatic, adLockReadOnly

If rsTable.RecordCount > 0 Then
    rsTable.MoveFirst
    ListView1.ListItems.Clear
    ListView1.ColumnHeaders.Add , , "ID"
    ListView1.ColumnHeaders.Add , , "Customer Name"
    ListView1.ColumnHeaders.Add , , "Address"
    ListView1.ColumnHeaders.Add , , "Pincode"
    ListView1.ColumnHeaders.Add , , "Amount"

    Do While Not rsTable.EOF
        Counter = ListView1.ListItems.Count + 1
        Set list = ListView1.ListItems.Add(, , Counter)
        list.ListSubItems.Add , , rsTable!CUSTOMERNAME
        list.ListSubItems.Add , , rsTable!ADDRESS1
        list.ListSubItems.Add , , rsTable!pin
        list.ListSubItems.Add , , rsTable!LOAN_AMOUNT
        rsTable.MoveNext
    Loop
Else
    MsgBox "No record found in the table.", vbCritical

End If

If rsTable.State = 1 Then rsTable.Close
If xCon.State = 1 Then xCon.Close
MsgBox "Record Add Successfully", vbInformation
Related