Function GetData(ByVal Sql As String) As String
Dim ado As New ADODB.Connection
Dim rs As New ADODB.Recordset
ado.Open "Provider=SQLOLEDB.1;Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=voice;Data Source=192.168.0.3"
rs.CursorLocation = adUseClient
rs.Open Sql, ado, 1, 1
If rs.getstring Then
GetData = rs.getstring
rs.Close
ado.Close
Set rs = Nothing
Set ado = Nothing
Else
rs.Close
ado.Close
Set rs = Nothing
Set ado = Nothing
ado.Open "Provider=SQLOLEDB.1;Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=voice;Data Source=192.168.0.111"
rs.CursorLocation = adUseClient
rs.Open Sql, ado, 1, 1
If rs.getstring Then
GetData = rs.getstring
rs.Close
ado.Close
Set rs = Nothing
Set ado = Nothing
Else
MsgBox = "没有记录!"
rs.Close
ado.Close
Set rs = Nothing
Set ado = Nothing
End If
rs.Close
ado.Close
Set rs = Nothing
Set ado = Nothing
End If
End FunctionPrivate Sub Command1_Click()
Me.Text2.Text = GetData("select top 50 id from fu_dianhuayingxiao where callee=" & Text1.Text)
Me.Text3.Text = GetData("select top 50 gonghao from fu_dianhuayingxiao where callee=" & Text1.Text)
Me.Text4.Text = GetData("select top 50 caller from fu_dianhuayingxiao where callee=" & Text1.Text)
Me.Text5.Text = GetData("select top 50 callee from fu_dianhuayingxiao where callee=" & Text1.Text)
Me.Text6.Text = GetData("select top 50 begintime from fu_dianhuayingxiao where callee=" & Text1.Text)
Me.Text7.Text = GetData("select top 50 endtime from fu_dianhuayingxiao where callee=" & Text1.Text)
Me.Text8.Text = GetData("select top 50 calloutcount from fu_dianhuayingxiao where callee=" & Text1.Text)
Me.Text9.Text = GetData("select top 50 issend from fu_dianhuayingxiao where callee=" & Text1.Text)
Me.Text10.Text = GetData("select top 50 dingzhiid from fu_dianhuayingxiao where callee=" & Text1.Text)
Me.Text11.Text = GetData("select top 50 beizhu from fu_dianhuayingxiao where callee=" & Text1.Text)
End Sub这段代码在运行时出错,提示“用户定义类型为定义”
请大虾们帮我看看是哪里出错了。
在下在这里先谢谢了。
谢谢。
谢谢。

解决方案 »

  1.   

    缺少引用
    看看ado是否引用了
      

  2.   

    引用了 
    microsoft DAO 2.5/3.51 compatibitity library
      

  3.   

    ```Public Con As New ADODB.Connection
    Public rst As New ADODB.RecordsetPublic Sub DataBaseConnection()
        If Con.State = adStateClosed Then
            Con.Open "Provider=MSDASQL.1;Persist Security Info=False;User ID=sa;Data Source=QQsystem"
        End If
    End Sub
    Public Sub DateBaseRec(SQLstring As String)
        If rst.State = adStateOpen Then
            rst.Close
        End If    With rst
            .CursorLocation = adUseClient
            .CursorType = adOpenDynamic
            Debug.Print SQLstring
            .Open SQLstring, Con, , adLockBatchOptimistic, adCmdText
        End WithEnd SubPublic Sub NewAdo(NewADOrec As ADODB.Recordset, SQLstring As String)    If NewADOrec.State = adStateOpen Then
            NewADOrec.Close
        End If    With NewADOrec
            .CursorLocation = adUseClient
            .CursorType = adOpenDynamic
            Debug.Print SQLstring
            .Open SQLstring, Con, , adLockBatchOptimistic, adCmdText
        End WithEnd Sub
    Public Function DateBaseRecNew(SQLstring As String) As Boolean
        If rst.State = adStateOpen Then
            rst.Close
        End If
        
        On Error GoTo BadRecode
        
        With rst
            .CursorLocation = adUseClient
            .CursorType = adOpenDynamic
            Debug.Print SQLstring
            .Open SQLstring, Con, , adLockBatchOptimistic, adCmdText
        End With
        
        DateBaseRecNew = True
        
        Exit Function
    BadRecode:
        DateBaseRecNew = False
    End Function
      

  4.   

    Provider=SQLOLEDB.1改:Provider=SQLOLEDB
      

  5.   

    hunter086() ( ) 信誉:100    Blog  2007-3-23 8:22:45  得分: 0  
     
     
       
    引用了 
    microsoft DAO 2.5/3.51 compatibitity library
    ---
    错了
    应该引用ADO
      
     
      

  6.   

    引用
    microsoft Activex Data Objects (2.8) library
    (2.8)为版本号,根据自己的需要来选择
      

  7.   

    引用了 
    microsoft DAO 2.5/3.51 compatibitity library
    改为在工程-》引用-》microsoft Activex Data Objects (2.8) library