Private Sub AccessData(ByVal tableVar As String, ByVal FieldVar As String, ByVal var1 As String, ByVal var2 As String)
Dim strSQLcheck As String
Set connHope = New ADODB.Connection
Set rsHope = New ADODB.Recordset
rsHope.MaxRecords = 10
If var2 = "" Then
Select Case Combo2.Text
Case "销售单价", "进货价", "货存量", "最近入货日期", "销售额", "出售时间", "进货量", "进货日期", "销售数量"
strSQLcheck = "select * from " & tableVar & " where " & FieldVar & " =" & var1
Case Else
strSQLcheck = "select * from " & tableVar & " where " & FieldVar & " ='" & var1 & "'"
End Select
Else
strSQLcheck = "select * from " & tableVar & " where " & FieldVar & " >= #" & CDate(var1) & "# and " & FieldVar & " <= #" & CDate(var2) & "#"
End If
' MsgBox strSQLcheck 'passed
connHope.CursorLocation = adUseClient
Call PubConnSub(connHope, rsHope, strSQLcheck, 1, 1)
rsHope.PageSize = 10
rsHope.AbsolutePage = 1
' MsgBox "have connected databse" 'passed
If rsHope.EOF = True Then
rsHope.Close
Set rsHope = Nothing
connHope.Close
Set connHope = Nothing
MsgBox "没相关记录!"
Else
DataGrid1.Caption = "共查询到" & CStr(rsHope.RecordCount) & " 条符合条件的记录"
Set DataGrid1.DataSource = rsHope
DataGrid1.Refresh
End If
End Sub
已经正确显示数据库里的数据了,但是由于考虑到当符合查询条件的记录太庞大的时候,对内存的消耗太厉害了,所以想实现分页显示,但是写了一下不成功:
rshope recordset对象打开之前还设置了:
rsHope.MaxRecords = 50
打开后设置了:
rsHope.PageSize = 10
rsHope.AbsolutePage = 1
但是都没有效果,数据库中有100条记录,一查询后,datagrid中就依然显示100条记录然后按钮"NextPage"的click事件
Private Sub Command2_Click()
If rsHope.AbsolutePage < rsHope.PageCount Then
rsHope.AbsolutePage = rsHope.AbsolutePage + 1
rsHope.MoveFirst
DataGrid1.Refresh
esle
Command2.Enabled = False
End If
End Sub
Private Sub Command2_Click()
结果:这个过程出错,编译错误!
希望高手多多指点!
Dim strSQLcheck As String
Set connHope = New ADODB.Connection
Set rsHope = New ADODB.Recordset
rsHope.MaxRecords = 10
If var2 = "" Then
Select Case Combo2.Text
Case "销售单价", "进货价", "货存量", "最近入货日期", "销售额", "出售时间", "进货量", "进货日期", "销售数量"
strSQLcheck = "select * from " & tableVar & " where " & FieldVar & " =" & var1
Case Else
strSQLcheck = "select * from " & tableVar & " where " & FieldVar & " ='" & var1 & "'"
End Select
Else
strSQLcheck = "select * from " & tableVar & " where " & FieldVar & " >= #" & CDate(var1) & "# and " & FieldVar & " <= #" & CDate(var2) & "#"
End If
' MsgBox strSQLcheck 'passed
connHope.CursorLocation = adUseClient
Call PubConnSub(connHope, rsHope, strSQLcheck, 1, 1)
rsHope.PageSize = 10
rsHope.AbsolutePage = 1
' MsgBox "have connected databse" 'passed
If rsHope.EOF = True Then
rsHope.Close
Set rsHope = Nothing
connHope.Close
Set connHope = Nothing
MsgBox "没相关记录!"
Else
DataGrid1.Caption = "共查询到" & CStr(rsHope.RecordCount) & " 条符合条件的记录"
Set DataGrid1.DataSource = rsHope
DataGrid1.Refresh
End If
End Sub
已经正确显示数据库里的数据了,但是由于考虑到当符合查询条件的记录太庞大的时候,对内存的消耗太厉害了,所以想实现分页显示,但是写了一下不成功:
rshope recordset对象打开之前还设置了:
rsHope.MaxRecords = 50
打开后设置了:
rsHope.PageSize = 10
rsHope.AbsolutePage = 1
但是都没有效果,数据库中有100条记录,一查询后,datagrid中就依然显示100条记录然后按钮"NextPage"的click事件
Private Sub Command2_Click()
If rsHope.AbsolutePage < rsHope.PageCount Then
rsHope.AbsolutePage = rsHope.AbsolutePage + 1
rsHope.MoveFirst
DataGrid1.Refresh
esle
Command2.Enabled = False
End If
End Sub
Private Sub Command2_Click()
结果:这个过程出错,编译错误!
希望高手多多指点!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货