Database VB6.0将记录添加到数据库(Listview)

Database VB6.0将记录添加到数据库(Listview),database,listview,vb6,transactions,Database,Listview,Vb6,Transactions,每次单击此命令时,我都会出错。我试图将交易历史记录放在TransactionNo和Earnings字段上,其他字段仅用于库存 Private Sub Command1_Click() Dim earnings As Double earnings = txtCash - txtChange ConnectDB rs.Open "Select TransactionNo, Earnings from Table2", db, 3, 3 rs.AddNew rs(0) = txtNumber

每次单击此命令时,我都会出错。我试图将交易历史记录放在TransactionNo和Earnings字段上,其他字段仅用于库存

Private Sub Command1_Click()
Dim earnings As Double
earnings = txtCash - txtChange
ConnectDB
rs.Open "Select TransactionNo, Earnings from Table2", db, 3, 3
rs.AddNew
    rs(0) = txtNumber 'rs(1) is an auto number
     rs(2) = txtProduct 'Here i got an error, it says Item cannot be found in the 'collection corresponding to the requested name or ordinal
      rs(3) = txtStockLeft
       rs(4) = txtPricePiece
        rs(5) = txtExpiry
          rs(6) = earnings
rs.Update
Set rs = Nothing
db.Close: Set rs = Nothing
LoadData1
ListView2.ListItems.Clear
LoadData
这里有什么问题?

只需将代码rs2=txtProduct更改为rs1=txtProduct即可

当您按照我所说的更改代码时,您不会在该行中得到错误

但您将在下面的行中看到错误

rs(3) = txtStockLeft
rs(4) = txtPricePiece
rs(5) = txtExpiry

这是因为select查询仅返回两列select TransactionNo,表2中的收益。您需要包括其他相关列。

这有助于我选择所有列ConnectDB rs。打开表2、db、3、3,我只需使用0宽度和ListView2.ColumnHeaders隐藏其他数据。添加、ID、10.Add、数字、1000.Add、ProductName、0.Add、股票、0.Add、PricePiece、0.Add、到期日、0.Add、收益、1200