我通过MSHFlexgrid 通过条件查记录,记录大概有一万4000条,速度需要1分半,太慢,并且第二次查询时,记录只与最后一行,前面都空白
代码如下:Private Sub title1()
Dim L As Integer
m = Array(700, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500)
n = Array("序号", "工程号", "图档号", "板号", "条码", "尺寸", "颜色", "备注栏", "制程", "工作站")
For L = 0 To 9
   MS1.ColWidth(L) = m(L):   MS1.TextMatrix(0, L) = n(L)
Next LEnd Sub
Private Sub Command1_Click()
 MS1.Clear 
Call title1
Adodc1.ConnectionString = PublicStrAdodc1.RecordSource = "select * from scandata where 1=1"
If Text1.Text <> "" Then
Adodc1.RecordSource = Adodc1.RecordSource + " and gch='" + Text1.Text + "'"
End IfIf Text2.Text <> "" Then
Adodc1.RecordSource = Adodc1.RecordSource + " and tdh='" + Text2.Text + "'"
End If
Adodc1.Refresh
Text3.Text = Adodc1.Recordset.RecordCountIf Adodc1.Recordset.RecordCount > 0 Then Do While Adodc1.Recordset.EOF = False
 
 MS1.Rows = Adodc1.Recordset.RecordCount + 1
 On Error Resume Next
  
  
  MS1.TextMatrix(MS1.Row, 1) = Adodc1.Recordset.Fields("gch")
  MS1.TextMatrix(MS1.Row, 2) = Adodc1.Recordset.Fields("tdh")
  MS1.TextMatrix(MS1.Row, 3) = Adodc1.Recordset.Fields("bh")
  MS1.TextMatrix(MS1.Row, 4) = Adodc1.Recordset.Fields("barcode")
  MS1.TextMatrix(MS1.Row, 5) = Adodc1.Recordset.Fields("cc")
  MS1.TextMatrix(MS1.Row, 6) = Adodc1.Recordset.Fields("ys")
  MS1.TextMatrix(MS1.Row, 7) = Adodc1.Recordset.Fields("bzl")
  MS1.TextMatrix(MS1.Row, 8) = Adodc1.Recordset.Fields("zc")
  MS1.TextMatrix(MS1.Row, 9) = Adodc1.Recordset.Fields("stationName")
  Adodc1.Recordset.MoveNext
  j = j + 1
  MS1.AddItem (j)
 MS1.Row = MS1.Row + 1
  
  
  
  Loop End IfFor i = 1 To MS1.Rows
     MS1.TextMatrix(i, 0) = i
     
  Next i
  
  
End SubPrivate Sub Form_Load()
Call title1End Sub
MSHFLEXGRID

解决方案 »

  1.   

    MSHFlexgrid没有item重用功能,你查出多少数据就会生成多少个item对象,所以建议加一个分页查询的功能
      

  2.   

    把 MSHFlexGrid 与 Adodc1 直接绑定,不要逐记录写入。每次查询后,刷新  MSHFlexGrid。
      

  3.   

    If Adodc1.Recordset.RecordCount > 0 Then
        set ms1.datasource=adodc1.recordset
    end if
      

  4.   

    谢谢,按3楼所写,运行中提示:
    实时错误91,对象变量或WITH块变量末设置
    set ms1.datasource=adodc1.recordset 变黄
      

  5.   

    放在你的代码中
    ......
    Adodc1.Refresh
    If Adodc1.Recordset.RecordCount > 0 Then
        set ms1.datasource=adodc1.recordset
    end if
      

  6.   

    Private Sub Command1_Click() MS1.Clear 
    Call title1
    Adodc1.ConnectionString = PublicStrAdodc1.RecordSource = "select * from scandata where 1=1"
    If Text1.Text <> "" Then
    Adodc1.RecordSource = Adodc1.RecordSource + " and gch='" + Text1.Text + "'"
    End IfIf Text2.Text <> "" Then
    Adodc1.RecordSource = Adodc1.RecordSource + " and tdh='" + Text2.Text + "'"
    End If
    Adodc1.Refresh
    'Text3.Text = Adodc1.Recordset.RecordCount
    '
     If Adodc1.Recordset.RecordCount > 0 Then
      Set MS1.DataSource = Adodc1 
      MS1.Rows = Adodc1.Recordset.RecordCount + 1  
        
     End If
      
    End SubPrivate Sub Form_Load()
    Call title1End Sub
    Private Sub title1()
    Dim L As Integer
    m = Array(700, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500)
    n = Array("序号", "工程号", "图档号", "板号", "条码", "尺寸", "颜色", "备注栏", "制程", "工作站")
    For L = 0 To 9
       MS1.ColWidth(L) = m(L):   MS1.TextMatrix(0, L) = n(L)
    Next LEnd Sub还是没用 错误继续是实时错误91,对象变量或WITH块变量末设置
    对了意思,我的控件是msflexgrid 不是mshflexgrid 这两种有什么区别?
    谢谢
      

  7.   

    谢谢 ,用MSHFLEXGRID 可以