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
这段程序我怎么调也调不好,哪位大哥能帮帮我呀,小弟感激不尽!
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
这段程序我怎么调也调不好,哪位大哥能帮帮我呀,小弟感激不尽!
& "where 图书表.读者编号 =读者表.读者编号 and 读者表.读者编号=trim(textBH.text) and" _
& "读者表.读者名称 = trim(TextMC.Text)"
有问题吧!
strSQL = "select 图书编号,图书名称,出版社,作者,图书类别,借书时间 from 图书表,读者表" _
& "where 图书表.读者编号 =读者表.读者编号 and 读者表.读者编号='" & trim(textBH.text) & "' and" _
& "读者表.读者名称 = '" & trim(TextMC.Text) & "'"试试,其它地方可能也有问题
Set DataGrid1.DataSource = Recordset
最后一句有问题,recordset是什么???
应该是
Set DataGrid1.DataSource = rs
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
应该写成Set DataGrid1.DataSource =rs recordset是个类,而rs是个对象,我怎么能用类给datagrid传值能,嗨!太水了我。