Private Sub Form_Load()
cn.ConnectionString = "在此忽律太长"
cn.CursorLocation = adUseServer
cn.Open
End SubPrivate Sub Command1_Click()
dim Sql as string
Sql="select * from yh where sName like " & "'" & text1.text & "'"   
rs.open Sql,cn,1,1
set DataGrid1.date.DataSource=rs
rs.close
End Sub
'cn是ADODB.Connection对象 rs是ADODB.Recordset 对象,都在类模块中声明,为什么DataGrid1中就显示不出数据呢???

解决方案 »

  1.   

    Sql="select * from yh where sName like " & "'" & text1.text & "'"   
    这句错了
      

  2.   

    Sql="select * from yh where sName like " & "'" & text1.text & "'"  
    set DataGrid1.date.DataSource=rs 这句话错了
      

  3.   

    Private Sub Form_Load()
    cn.ConnectionString = "在此忽律太长"
    cn.CursorLocation = adUseServer
    cn.Open
    End SubPrivate Sub Command1_Click()
    dim Sql as string
    Sql="select * from yh where sName like '%" & text1.text & "%'"
    rs.CursorLocation = adUseClient   
    rs.open Sql,cn,1,1
    set DataGrid1.DataSource=rs
    datagrid1.Refresh 
    rs.close
    End Sub改成上面的代码试试
      

  4.   

    谢谢大家了,我把rs.close去掉了就可以了,但不晓得是为什么