所以我对VBA很新,所以我不太清楚我为什么会收到错误“Recordset无法编入索引因为没有默认属性”。事情是几小时前在另一台电脑上工作,所以有什么想法吗?
Public Class Form1 Public Conn As New ADODB.Connection Public RS As New ADODB.Recordset
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim i As Integer
Dim SQL
RS = New ADODB.Recordset
RS.CursorType = ADODB.CursorTypeEnum.adOpenKeyset
RS.LockType = ADODB.LockTypeEnum.adLockOptimistic
SQL = "SELECT P.descripcion, P.precio FROM Producto P, CATEGORIAS C WHERE C.idcat= P.idcategoria and Idcat=" & TextBox1.Text
RS.Open(SQL, Conn, , , ADODB.CommandTypeEnum.adCmdText)
i = 0
ListView1.Items.Clear()
If RS.EOF() Then
MsgBox("NO hay productos registrados para esa Categoría")
Else
Do While Not RS.EOF()
ListView1.Items.Add(RS(0).Value)
ListView1.Items(i).SubItems.Add(RS(1).Value)
i = i + 1
RS.MoveNext()
Loop
End If
End Sub