比如id  name 
    1   wang
    2   li
我想判断2是否存在,如果存在则修改name,怎么操作呢??

解决方案 »

  1.   

    Dim rs As New ADODB.Recordset
    rs.CursorLocation = adUseClient 
    rs.open "select id from tablename where id=2",conn
    if rs.RecordCount>0 then
        '修改
    else
        '不存在
    end if
      

  2.   

    查找id为2的记录
    rst.open "select * from table where id=2",返回为空就AddNew。不为空就直接UpDate
      

  3.   

    我写得比较复杂,请XDJM指教:
          Adodc1.Recordset.MoveFirst
          Adodc1.Recordset.Find "name=li"
          If Not Adodc1.Recordset.EOF Then
            MsgBox "已找到该姓名!" 
            text1.SetFocus
          End If
      

  4.   

    就是想问具体的update 语句怎么写
      

  5.   

    dim tempName as string
    tempName="修改的名"
    conn.Execute "update tablename set [name]='"& tempName &"' where id=2"
      

  6.   

    rst.Fields("name") = "修改的名字"
    rst.update
      

  7.   

    为什么.RecordCount返回总是为-1呢?不管有没有记录都返回的是-1请各位指点一下,代码如下:
    DBRoomStatus 为记录集
    Set DBRoomStatus = DBConnection.Execute("select * from RoomStatus where Room =' "Trim(StrCurrentFloor & StrCurrentRoom)" '") If DBRoomStatus.RecordCount > 0 Then
        DBConnection.Execute "update RoomStatus set [StatusData]='" & StrInput & "' where Room ='" & Trim(StrCurrentFloor & StrCurrentRoom) & "'"
        DBConnection.Execute "update RoomStatus set [InputTime]= Now where Room ='" & Trim(StrCurrentFloor & StrCurrentRoom) & "'"                                                         
        Else
       DBConnection.Execute ("insert into RoomStatus(Room,StatusData,InputTime) values('" & Trim(StrCurrentFloor & StrCurrentRoom) & "','" & StrInput & "','" & StrTime & "') ")
     End If
    DBRoomStatus.RecordCount 返回的始终是-1,为什么?
      

  8.   

    conn.Execute "update tablename set [name]='"& strtemp &"' where id=2"这个最简单了。^_^
      

  9.   

    另外:这两句update可以合为一句吗?怎么写啊?
    DBConnection.Execute "update RoomStatus set [StatusData]='" & StrInput & "' where Room ='" & Trim(StrCurrentFloor & StrCurrentRoom) & "'"
        DBConnection.Execute "update RoomStatus set [InputTime]= Now where Room ='" & Trim(StrCurrentFloor & StrCurrentRoom) & "'"
      

  10.   

    Set DBRoomStatus = DBConnection.Execute("select * from RoomStatus where Room =' "Trim(StrCurrentFloor & StrCurrentRoom)" '")
    DBRoomStatus.MoveLast 
    ......
      

  11.   

    DBRoomStatus.CursorLocation=adUseClient
    --------------------
    为什么.RecordCount返回总是为-1呢?不管有没有记录都返回的是-1
      

  12.   

    如果楼主用sql server的话可以这样写
    if exists (update tablename set [name]='"& tempName &"' where id=2 )
         update tablename set ...........
    else
         insert into tablename以上在sql server 里是算一句sql语句你只要这样用就行了。如果不是sql server就看看楼上各位吧