我向DataGrid里添加记录时,会出现错误提示"书签错误!"为何?

解决方案 »

  1.   

    Frm_3_Sell 窗体
    '---- 搜索满足条件的商品记录,显示在 Frm_3_Sell_select窗体的DataGrid1 中
    Private Sub Command1_Click()
    conn.Open strconn '---- Public conn As New ADODB.Connection  在模块中定义的;
    Dim rs_Find As New ADODB.RecordsetDim str As String
            '------------------------ 设置了 产品、品牌、型号 条件
    str = "select 货号,产品,品牌,型号,单位,单价 from 商品清单 where  产品='" + Trim(DataCombo1.Text) + "'and 品牌='" + Trim(DataCombo2.Text) + "' and 型号='" + Trim(DataCombo3.Text) + "'"
     
      rs_Find.Open str, conn, adOpenStatic, adLockPessimistic
      If rs_Find.RecordCount > 0 Then
          Set Frm_3_Sell_select.DataGrid1.DataSource = rs_Find
          Frm_3_Sell_select.Show 1
        Else
          MsgBox "抱歉,我们没有您想要的产品!" & vbCrLf & " 请确认要查找的条件! "
          rs_Find.Close
          Exit Sub
      End If
    End SubFrm_3_Sell_select窗体
    Private Sub Command1_Click()
    '---- 把顾客选择的产品添加到Frm_3_Sell窗体中
         Frm_3_Sell.rs2.AddNew
       Frm_3_Sell.rs2.Fields("货号") = Int(Frm_3_Sell.rs2.RecordCount + 1)
       Frm_3_Sell.rs2.Fields("产品") = Frm_3_Sell.rs_Find.Fields("产品")
       Frm_3_Sell.rs2.Fields("品牌") = Frm_3_Sell.rs_Find.Fields("品牌")
       Frm_3_Sell.rs2.Fields("型号") = Frm_3_Sell.rs_Find.Fields("型号")
       Frm_3_Sell.rs2.Fields("单位") = Frm_3_Sell.rs_Find.Fields("单位")
       Frm_3_Sell.rs2.Fields("单价") = Frm_3_Sell.rs_Find.Fields("单价")
       Frm_3_Sell.rs2.Fields("数量") = Text1.Text
       Frm_3_Sell.rs2.Fields("应付款") = Frm_3_Sell.rs_Find.Fields("单价")    
       Frm_3_Sell.rs2.Update
       Unload Me
    End Sub
    '当点击Frm_3_Sell_select窗体的 Command1时,提示错误"书签无效!"
    '两个窗体中的字段名相同,也设置了主键
      

  2.   

    在这句前rs_Find.Open str, conn, adOpenStatic, adLockPessimistic
    加rs_Find.CursorLocation = adUseClient看行不行