用户定义类型未定义 我加了引用了还是不行,请问是怎么回事啊?////////////////////////////////////////把代码贴上来
Private Sub Command1_Click()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strCnn As String
Dim t_name As Stringt_name = Trim(t_text.Text)
strCnn = " DRIVER={SQL SERVER};SERVER=hu;DATABASE=xkxt"
Set cn = New ADODB.Connection//////////////////这里说是用户定义类型未定义
cn.Open strCnn
strSQL = " select cn from sc,student,course where  sc.sno=student.sno and  " + _
           " sc.cno=course.cno and studnet.sn=' " + t_name + " ' "
Set rs = New ADODB.Recordest
rs.CursorType = adOpenStatic
rs.CursorLocation = adUseClient
Set rs = cn.Execute(strSQL)
Do While rs.EOF = Flase
     List1.AddItem rs!cname
     rs.MoveNext
Loop
Set rs = Nothing
cn.Close
Set cn = NothingEnd Sub

解决方案 »

  1.   

    strSQL = " select cn from sc,student,course where  sc.sno=student.sno and  " + _ 
              " sc.cno=course.cno and studnet.sn=' " + t_name + " ' " 
    改成
    strSql = " select cn from sc,student,course where  sc.sno=student.sno and  " + _
              " sc.cno=course.cno and studnet.sn='" + t_name + "' "你的t_name旁边多两个空格 
      

  2.   

    strSQL = " select cn from sc,student,course where  sc.sno=student.sno and  " + _ 
              " sc.cno=course.cno and studnet.sn=' " + t_name + " ' "  List1.AddItem rs!cname 这两个有矛盾
    需要改一下
      

  3.   

    引用的Microsoft ActiveX Data Objects 2.6 Library请问对吗?
      

  4.   

    strSQL = " select cn from sc,student,course where  sc.sno=student.sno and  " + _ 
              " sc.cno=course.cno and studnet.sn=' " + t_name + " ' " 
      

  5.   

    引用没有问题
    很怪的问题
    Set cn = New ADODB.Connection
    Set rs = New ADODB.Recordset
    我用你的就不好用
    我自己输入就好用
    看不出差别
    有可能输入法的问题Private Sub Command1_Click() 
    Dim cn As ADODB.Connection 
    Dim rs As ADODB.Recordset 
    Dim strCnn As String 
    Dim t_name As String t_name = Trim(t_text.Text) 
    strCnn = " DRIVER={SQL SERVER};SERVER=hu;DATABASE=xkxt" 
    Set cn = New ADODB.Connection   '//////////////////这里说是用户定义类型未定义 
    cn.Open strCnn 
    strSQL = " select cn from sc,student,course where  sc.sno=student.sno and  " + _ 
              " sc.cno=course.cno and studnet.sn='" + t_name + "' " 
    Set rs = New ADODB.Recordset 
    rs.CursorType = adOpenStatic 
    rs.CursorLocation = adUseClient 
    Set rs = cn.Execute(strSQL) 
    Do While rs.EOF = Flase 
        List1.AddItem rs!cn 
        rs.MoveNext 
    Loop 
    Set rs = Nothing 
    cn.Close 
    Set cn = Nothing End Sub