0

您好我正在使用 vb6 ms 访问后端,而不是更新它复制并创建一个新条目的记录。由于与其他表的关系,我的表不使用主键。我怎样才能让它更新记录而不是重复这里是我的代码

Private Sub cmdSave_Click()
With Connect.rsitem
       .Open , , adOpenDynamic, adLockOptimistic
        If EditItem = False Then .AddNew
           !itemno = txtItemNo.Text
           !desc1 = txtDesc1.Text
           !desc2 = txtDesc2.Text
           !onhandqty = txtOnhandQty.Text
           !unitprice = txtUnitPrice.Text
           !Size = txtSize.Text
           !upc = txtupc.Text
           !Ordercost = txtOrderCost.Text
   .Update
   .Close
End sub
4

1 回答 1

1

请先选择查询..

Dim rs As DAO.Recordset

rs.Open "SELECT * FROM mytable WHERE itemno = '" & txtItemNo.Text & "'"
If Not rs.BOF and Not rs.EOF then

  'save the record ......

End If
If rs.State = adStateOpen Then rs.Close
Set rs = Nothing
于 2013-05-27T11:40:44.803 回答