Dim rs As New ADODB.Recordset
Dim cn As New ADODB.Connection
Private Sub Command1_Click()
  Dim strSQL As String
  cn.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=图书管理;Data Source=1MCPC012"
  cn.CursorLocation = adUseClient
  strSQL = "select 图书编号,图书名称,出版社,作者,图书类别,借书时间 from 图书表,读者表" _
           & "where 图书表.读者编号 =读者表.读者编号 and 读者表.读者编号=trim(textBH.text) and" _
           & "读者表.读者名称 = trim(TextMC.Text)"
rs.Open strSQL, cn, adOpenKeyset, adLockPessimistic
Set DataGrid1.DataSource = Recordset
End Sub
这段程序我怎么调也调不好,哪位大哥能帮帮我呀,小弟感激不尽!

解决方案 »

  1.   

    //strSQL = "select 图书编号,图书名称,出版社,作者,图书类别,借书时间 from 图书表,读者表" _
               & "where 图书表.读者编号 =读者表.读者编号 and 读者表.读者编号=trim(textBH.text) and" _
               & "读者表.读者名称 = trim(TextMC.Text)"
    有问题吧!
    strSQL = "select 图书编号,图书名称,出版社,作者,图书类别,借书时间 from 图书表,读者表" _
               & "where 图书表.读者编号 =读者表.读者编号 and 读者表.读者编号='" & trim(textBH.text) & "' and" _
               & "读者表.读者名称 = '" & trim(TextMC.Text) & "'"试试,其它地方可能也有问题
      

  2.   

    where 前边加一个空格,and后边加一个空格。
      

  3.   

    对了,我说的是 rainstormmaster(rainstormmaster) 修改后的语句。你原来的语句错误太明显了。
      

  4.   

    rs.Open strSQL, cn, adOpenKeyset, adLockPessimistic
    Set DataGrid1.DataSource = Recordset
    最后一句有问题,recordset是什么???
    应该是
    Set DataGrid1.DataSource = rs
      

  5.   

    好了,调试通过Dim rs As New ADODB.Recordset
    Dim cn As New ADODB.Connection
    Private Sub Command1_Click()
      Dim strSQL As String
      cn.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=图书管理;Data Source=1MCPC012"
      cn.CursorLocation = adUseClient
      strSQL = "select 图书编号,图书名称,出版社,作者,图书类别,借书时间 from 图书表,读者表 "
      strSQl=strSQl & " where 图书表.读者编号 =读者表.读者编号 and 读者表.读者编号='" & trim(textBH.text) &"' and "
      strSQL=strSQL  & " 读者表.读者名称 = '"& trim(TextMC.Text) &"'"
      rs.Open strSQL, cn, adOpenKeyset, adLockPessimistic
      Set DataGrid1.DataSource = rs
      DataGrid1.Refresh
    end sub
      

  6.   

    谢谢各位,我的问题解决了。是这一句出错了Set DataGrid1.DataSource = Recordset
    应该写成Set DataGrid1.DataSource =rs recordset是个类,而rs是个对象,我怎么能用类给datagrid传值能,嗨!太水了我。