参考:
Dim rsUSER As ADODB.Recordset
Dim SQLstmt As String
Set PALUSADBCon = New ADODB.Connection
PALUSADBCon.ConnectionTimeout = 3000
PALUSADBCon.Open "Provider=MSDataShape.1;Persist Security Info=true;Data Source=172.#.#.#;User ID=pusa; Password =usa; Initial Catalog=PALUSASDS;Data Provider=SQLOLEDB.1"Set dbRs = New ADODB.Recordset
SQLstmt = " select * From vbak where SHPIN4='SEA' " & _
        "and ordnum=(select top 1 ordnum From JOIT where caseno = " & _
        " (select top 1 caseno from cast where loadid='" & LOADID & "'))"SQLstmt = " select climat,count(climat) as QTY From JOIT " & _
        " where caseno in ( " & _
        " select caseno " & _
        " from cast where loadid='" & LOADID & "'" & _
        " ) " & _
        " group by climat "

解决方案 »

  1.   

    Adodc1.recordsource = "select * from 人员库 where 人员ID ='" & gjz &"'"
      

  2.   

    Private Sub Command1_Click()
    gjz = trim(Text6.Text)
    Select Case Label6.Caption = " 人员ID"
    Adodc1.recordsource = "select * from 人员库 where 人员ID =" & cint(gjz)
    Case Label6.Caption = "工号"
    adodc1.RecordSource = "select * from 人员库 where 工号 ='" & gjz & "'"
    Case Label6.Caption = "姓名"
    adodc1.RecordSource = "select * from 人员库 where 姓名 ='" & gjz & "'"
    End Select
      

  3.   

    要是字段类型都是nvarchar/varchar的话:Private Sub Command1_Click()    adodc1.RecordSource = "select * from 人员库 where " & _
                               label6.caption & " ='" & trim(Text6.Text) & "'"End Select
      

  4.   

    順便問個問題,在proc 中,set nocount 有何意義?還有其他的set 選項嗎?
      

  5.   

    Private Sub Command1_Click()
    gjz = trim(Text6.Text)
    Select Case Label6.Caption 
    Case  "人员ID"
    Adodc1.recordsource = "select * from 人员库 where 人员ID =" & cint(gjz)
    Case  "工号"
    adodc1.RecordSource = "select * from 人员库 where 工号 ='" & gjz & "'"
    Case  "姓名"
    adodc1.RecordSource = "select * from 人员库 where 姓名 ='" & gjz & "'"
    End Select
      

  6.   

    在adodc1.RecordSource=的后面语句应是字符串!