Public Function UConnect(ByVal c As ADODB.Connection, ByVal R As ADODB.Recordset, ByVal s As String) As Boolean
On Error GoTo wwwww
  c.Open "driver=sql server;server=" & sqlserverming & ";uid=" & sqlsa & ";pwd=" & sqlpswd & ";database=xxgl"
  R.Open s, c, 3, 3
  If R.EOF Then
  UConnect = False
  Else
  UConnect = True
  End If
  Exit Function
wwwww:
  UConnect = False
End FunctionPublic Function DeConnecta(ByVal c As ADODB.Connection)
c.Close
Set c = Nothing
End Function这两个函数在 标准模块里面
MS 为表格的名称
执行代码如下:If MsgBox("您确信" + Chr(13) + "生产框号为:" & Trim(ms.TextMatrix(ms.Row, 9)) + Chr(13) + " 客户名称 为" & Trim(ms.TextMatrix(ms.Row, 1)) + Chr(13) + " 0道修磨工序已完成吗?", vbYesNo, "系统提示") = vbYes Then
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
If UConnect(cn, rs, "select * from gyscjd where kh= '" & Trim(ms.TextMatrix(ms.Row, 9)) & "' and gybh= '" & Trim(ms.TextMatrix(ms.Row, 12)) & "' and daoc=0") Then
rs.Fields("wc") = 1 '''''完成情况
rs.Fields("wczs") = Val(Trim(ms.TextMatrix(ms.Row, 10))) '''''完成支数
rs.Fields("wcsj") = Format(Date, "yy-mm-dd") '''''完成日期
rs.Update
DeConnecta cn
MsgBox "数据更新成功!", vbInformation, "系统提示"
Else
DeConnecta cn
Exit Sub
End If
---------------------------------完成前道任务的时间
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
If UConnect(cn, rs, "select headwc from gyscjd where kh= '" & Trim(ms.TextMatrix(ms.Row, 9)) & "' and gybh= '" & Trim(ms.TextMatrix(ms.Row, 12)) & "' and daoc=1") Then
rs.Fields("headwc") = 1
rs.Update
DeConnecta cn
Else
DeConnecta cn
End If
--------------------------------------更新后到任务的 HEADWC 字段值
End If如果只更新前面的一条记录的话,后面这个不更新的话,没有问题 查询数据库 只更新了以条记录。
如果两个一起执行的话,结果表中所有记录的 HEADWC 这个字段的值 全部更新为 1 了 ,请问是什么问题?
我以前做过触发器,但是现在我全部删除了呀? 请高手指教!!!!!!
  

解决方案 »

  1.   

    gyscjd 你这个表格里面的主键是哪个?
    If UConnect(cn, rs, "select headwc from gyscjd where kh= '" & Trim(ms.TextMatrix(ms.Row, 9)) & "' and gybh= '" & Trim(ms.TextMatrix(ms.Row, 12)) & "' and daoc=1") Then
    你看看这里的rs.recordcount你一定取出了多条记录
      

  2.   

    http://download.csdn.net/source/1498324
      

  3.   

    if UConnect(cn, rs, "select headwc from gyscjd where kh= '" & Trim(ms.TextMatrix(ms.Row, 9)) & "' and gybh= '" & Trim(ms.TextMatrix(ms.Row, 12)) & "' and daoc=1") Then
    这里查出来的应该是你说的变为1的全部记录。rs.Fields("headwc") = 1
    rs.Update
    这里执行了更新操作。