ADO对象,ADO控件,怎么查找一条记录?

解决方案 »

  1.   

    Dim gConn As ADODB.Connection
    Dim rst As ADODB.Recordset
    Dim strSQL As String
    Private Sub Command1_Click()
        Set gConn = New ADODB.Connection
        Set rst = New ADODB.Recordset
        gConn.Open "DSN=FAB_WLPH;UID=sa;PWD="
        rst.ActiveConnection = gConn
        rst.CursorLocation = adUseClient
        rst.CursorType = adOpenStatic
        strSQL = "select ID as 编号 , CZYName " & _
        "as 用户名 , czypwd as 密码 ,czylevel as 标识 from TblAdmin"
        rst.Open strSQL, gConn, adOpenKeyset, adLockOptimistic
    End Sub
      

  2.   

    Private Sub CmdFind_Click()
    On Error GoTo Err_DO
     Dim StrSql As String
     Dim strInStoreID As String '入库单号
     Dim strJSR As String '经手人
     Dim strSaleCompany As String '出品单位
     Dim strKindName As String '类别
     Dim strTypeName As String '类型
     Dim strGoodsID As String '商品编码
      Dim strGoodsName As String '商品名称
      
     Dim strInStoreDate As String '入库日期
     Dim strInStoreDateFrom As String
     Dim strInStoreDateTo As String
       StrSql = ""
          CmdFind.Enabled = False
          SngTotalMoney = 0
          LngTotalCount = 0
              
         Screen.MousePointer = vbHourglass
         If OpDetail.Value = True Then '次明细
             If frmMain.MenuUserRight.Enabled Then
                 StrSql = "select GoodsID as 商品编码,GoodsName as 商品名称,SaleCompany as 出品单位,PackageName as 包装," & _
                          "TypeName as 类型,KindName as 类别,UnitName as 单位,Quantity as 数量,InPrice as 进货单价," & _
                          "TotalMoney as 总金额,InStoreDate as 入库日期,JSR as 经手人,InStoreID as 入库单号" & _
                          " from TblInStoreDetail" & " where 1=1 "
                 Else
                 StrSql = "select GoodsID as 商品编码,GoodsName as 商品名称,SaleCompany as 出品单位,PackageName as 包装," & _
                          "TypeName as 类型,KindName as 类别,UnitName as 单位,Quantity as 数量,0 as 进货单价," & _
                          "0 as 总金额,InStoreDate as 入库日期,JSR as 经手人,InStoreID as 入库单号" & _
                          " from TblInStoreDetail" & " where 1=1 "
             End If
           ElseIf OpMaster.Value = True Then '主明细
             StrSql = "select InStoreID as 入库单号,InStoreDate as 入库日期,TotalMoney as 总金额," & _
                    " JSR as 经手人,SHFlag as 是否审核 from TblTotalInStore" & " where 1=1 "
             
         End If
            If ChkInStoreID.Value Then
               strInStoreID = " And InStoreID like '" & Trim(TxtInStoreID.Text) & "%'"
              Else
               strInStoreID = ""
            End If
            
            If ChkJSR.Value Then
               strJSR = " And JSR like '" & Trim(CboJSR.Text) & "%'"
              Else
               strJSR = ""
            End If
         If OpDetail.Value Then
             If ChkSaleCompany.Value Then
                strSaleCompany = " And SaleCompany like '" & Trim(CboFindSaleCompany.Text) & "%'"
               Else
                strSaleCompany = ""
             End If
             
             If ChkKindName.Value Then
                strKindName = " And KindName like '" & Trim(CboFindKindName.Text) & "%'"
               Else
                strKindName = ""
             End If
             If ChkTypeName.Value Then
                strTypeName = " And TypeName like '" & Trim(CboFindTypeName.Text) & "%'"
               Else
                strTypeName = ""
             End If
              If ChkGoodsID.Value Then
             strGoodsID = " And GoodsID like '" & Trim(TxtFindGoodsID.Text) & "%'"
            Else
             strGoodsID = ""
          End If
             If ChkGoodsName.Value Then
             strGoodsName = " And GoodsName like '" & Trim(TxtFindGoodsName.Text) & "%'"
            Else
             strGoodsName = ""
            End If
        End If
          
            If ChkInStoreDate.Value Then
                strInStoreDateFrom = Format(DTInStoreDateFrom.Value, "YYYY-MM-DD") & " 00:00:00"
                strInStoreDateTo = Format(DTInStoreDateTo.Value, "YYYY-MM-DD") & " 23:59:59"
                strInStoreDate = " And InStoreDate>='" & strInStoreDateFrom & "' and InStoreDate<='" & strInStoreDateTo & "'"
                
              Else
                strInStoreDate = ""
            End If
             
             '总的SQL语句
            If OpMaster.Value Then
              StrSql = StrSql & strInStoreID & strJSR & strSaleCompany & strKindName & strTypeName & strInStoreDate
            End If
             If OpDetail.Value Then
              StrSql = StrSql & strInStoreID & strJSR & strSaleCompany & strKindName & strTypeName & strInStoreDate & strGoodsID & strGoodsName
            End If
              
            If RstTblTotalInStore.State = adStateOpen Then RstTblTotalInStore.Close
            
              RstTblTotalInStore.CursorLocation = adUseClient
              RstTblTotalInStore.Open StrSql, conn, adOpenDynamic, adLockBatchOptimistic, 1
               Set DataGrid1.DataSource = RstTblTotalInStore
             
               Screen.MousePointer = vbDefault
             If OpDetail.Value Then Call subSetDataGridWidth1
             If OpMaster.Value Then Call subSetDataGridWidth2
             
          If RstTblTotalInStore.EOF And RstTblTotalInStore.BOF Then
                Screen.MousePointer = vbDefault
                MsgBox "未找到数据,请重新选择查询条件!!!", vbInformation + vbOKOnly, gcstMsgTitle
                CmdFind.Enabled = True
                CmdFind.SetFocus
                Exit Sub
         End If
        
             
                        
         '求总金额
          '求总金额
          If OpMaster.Value = True Then
             Do While Not RstTblTotalInStore.EOF
                SngTotalMoney = SngTotalMoney + RstTblTotalInStore("总金额") '总金额(入库明细)
                RstTblTotalInStore.MoveNext
             Loop
          End If
          If OpDetail.Value = True Then
             Do While Not RstTblTotalInStore.EOF
                LngTotalCount = LngTotalCount + RstTblTotalInStore("数量")
                SngTotalMoney = SngTotalMoney + RstTblTotalInStore("总金额") '总金额(入库明细)
                RstTblTotalInStore.MoveNext
             Loop
          End If     CmdFind.Enabled = True
         CmdFind.SetFocus
         Exit SubErr_DO:
         CmdFind.Enabled = True      Call subShowMessageEnd Sub
      

  3.   

    我看我的  ADO recordset对象有Seek方法和find方法,但是msdn没帮助,所以不动 请再赐教
      

  4.   

    Dim sFind As String
      sFind = " wonumber like '" & s_gl_Massage & "'"
      adoWO.Recordset.MoveFirst
      adoWO.Recordset.Find sFind, , adSearchForward
      If adoWO.Recordset.EOF Then
         MsgBox "未发现工作单号!"
        adoWO.Recordset.MoveFirst