读取数据一次太多10000多条数据,vb挂起了。怎么样解决。
我想分成几段来读取。应该怎么解决。
我的代码,应该怎么修改。请大家帮忙。
Public Function spare_model() As String '配件型号信息 Dim cn As New ADODB.Connection, Rs As New ADODB.Recordset cn.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;" & _ " Extended Properties='DSN=ascnew_2;SRVR=ascnew1214;DB=master;UID=dba;PWD=nokia&shangsi&asc'" cn.Open Rs.CursorLocation = adUseClient Rs.Open "SELECT T_SPARE_MODEL.c_spare_code,C_spare_name_local,c_spare_name_en,T_SPARE_MODEL.c_phone_model," & _"c_level_no,c_spare_model,c_warranty FROM T_SPARE_MODEL left join t_spare_part on " & _"t_spare_model.c_spare_code=t_spare_part.c_spare_code", cn, 3, 1 Dim stra As String While Not Rs.EOFstra = stra + Rs.Fields("c_spare_code") + "|" + Rs.Fields("C_spare_name_local") + "|" + _ Rs.Fields("c_spare_name_en") + "|" + Rs.Fields("c_phone_model") + "|" + _ Rs.Fields("c_level_no") + "|" + Rs.Fields("c_spare_model") + "|" + _ Rs.Fields("c_warranty") + "|"Rs.MoveNext WendForm1.Label3.Caption = Rs.Fields("c_spare_code").Count stra = stra & "spare_model" & "|" spare_model = stra Set Rs = Nothing Set cn = NothingEnd Function
While Not Rs.EOFstra = stra + Rs.Fields("c_spare_code") + "|" + Rs.Fields("C_spare_name_local") + "|" + _ Rs.Fields("c_spare_name_en") + "|" + Rs.Fields("c_phone_model") + "|" + _ Rs.Fields("c_level_no") + "|" + Rs.Fields("c_spare_model") + "|" + _ Rs.Fields("c_warranty") + "|"DoEventsRs.MoveNextWend
[解决办法]
可以用这个试试:
StringBuilder Class for VB
http://www.vbaccelerator.com/home/VB/code/Techniques/StringBuilder/article.asp
[解决办法]
我认为,这种一次性读取10000条记录的设计就是错的。
你可以每次读1000条呀,10次就行了。
具体要在sql语句中控制。
这就是“分页”