需要更新的数据记录在数据表中只有一条,而且数据表中也定义了主键,奇怪为什么会出现这种提示呢? 
实时错误 ‘-2147467259(80004005)’:键列信息不足或不正确。更新影响到多行
代码如下:
    Dim mrc1 As ADODB.Recordset
    txtsql = "select csflag ,tpflag from FNo0006  where dyleibieID=0 "
    Set mrc1 = ExecuteSQL(txtsql)
    If Combo4.Text = "黑白" Then
        mrc1.Fields("csflag").Value = "0"
    Else
        mrc1.Fields("csflag").Value = "1"
    End If
    If Check6.Value = 1 Then
       mrc1.Fields("tpflag").Value = True
    ElseIf Check6.Value = 0 Then
        mrc1.Fields("tpflag").Value = False
    End If
    mrc1.Update
    mrc1.Close

解决方案 »

  1.   

    如果你的表设定了主键的话
    可能因为你ExecuteSQL后mrc1包含了多行,你没有定位就直接修改值导致的。
      

  2.   

    我刚把ExecuteSQL函数(数据库连接函数,放在模块当中)中的 rst.CursorLocation = adUseClient  去掉以后问题就不会出现了,但不知道到底是什么原因?望高手帮忙解释一下
      

  3.   

    看来rst.CursorLocation = adUseClient还是不能去掉,否则在其它地方又会有新的问题发生
    怎样解决"键列信息不足或不正确。更新影响到多行"这种提示信息呢?
      

  4.   

    我把以上代码改为这种方式后就好了,但不知道为什么?并且感觉用这种方式判断真麻烦
    Dim mrc1 As ADODB.Recordset
       If Combo1.Text = "黑白" And Check1.Value = 1 Then
            txtsql = "update  FNo0006打印设定信息  set  csflag='0 ',tpflag=True  where  dyleibieID=5 "
            Set mrc1 = ExecuteSQL(txtsql)
       End If
       If Combo1.Text = "黑白" And Check1.Value = 0 Then
            txtsql = "update  FNo0006打印设定信息  set  csflag='0 ',tpflag=False  where  dyleibieID=5 "
            Set mrc1 = ExecuteSQL(txtsql)
       End If
       If Combo1.Text <> "黑白" And Check1.Value = 1 Then
            txtsql = "update  FNo0006打印设定信息  set  csflag='1 ',tpflag=True  where  dyleibieID=5 "
            Set mrc1 = ExecuteSQL(txtsql)
       End If
       If Combo1.Text <> "黑白" And Check1.Value = 0 Then
            txtsql = "update  FNo0006打印设定信息  set  csflag='1 ',tpflag=False  where  dyleibieID=5 "
            Set mrc1 = ExecuteSQL(txtsql)
       End If
      

  5.   

    txtsql = "select csflag ,tpflag from FNo0006  where dyleibieID=0 "你查到结果了吗?
      

  6.   

    To:wumylove1234(毁于随)
        我用msgbox mrc1.RecordCount   显示的结果为1  ,而且也查看了数据表中的确只有一条符合条件的记录To: linkinwork(白菜) 
        表中有主键
      

  7.   

    你的表中的数据是从两个表中提取的吗?
    如果是:
    则在Dim mrc1 As ADODB.Recordset
        后边,写上:
       mrc1.Properties.Item("unique table") = "FNo0006打印设定信息"
    试试看
      

  8.   

    告诉你吧,你需要把主键也select进来。例如:dyleibieID是主键
    "select dyleibieID,csflag ,tpflag from FNo0006  where dyleibieID=0 "对于查找的非主键rs,更新时就会出现如上现象,ok了吗