昨天按照您说的程序已经写完,但是发现一个问题,程序在执行过程中总是在访问数据库导致程序运行速度很慢,请问有什么方法可以改进吗?Private Sub Text1_Change(Index As Integer)Dim i As Integer    For i = 0 To 29
    
        Label_Name(i) = ""
        Set rs = cn.Execute("SELECT VarValue FROM STDNAME WHERE [STDNAME]='" & Text_Name(i) & "'")
        If Not rs.EOF Then Label_Name(i) = rs!VarValue & ""
        
    Next iEnd Sub

解决方案 »

  1.   

    在Change事件中访问数据库有点恐怖吧?
    而且你明明只修改了一个文本框,为啥要把所有30个标签都更新一遍呢?Private Sub Text1_Change(Index As Integer)'''Dim i As Integer    '''''For i = 0 To 29
        
            Label_Name(Index) = ""
            Set rs = cn.Execute("SELECT VarValue FROM STDNAME WHERE [STDNAME]='" & Text_Name(Index) & "'")
            If Not rs.EOF Then Label_Name(Index) = rs!VarValue & ""
            
        '''''Next iEnd Sub
      

  2.   

    不要循环,哪个变了查哪个:Private Sub Text1_Change(Index As Integer)         Label_Name(Index) = ""        If Len(Text_Name(Index)) <= 1 Theb Exit Sub '加上这句减少不必要查询        Set rs = cn.Execute("SELECT VarValue FROM STDNAME WHERE [STDNAME]='" & Text_Name(Index) & "'")        If Not rs.EOF Then Label_Name(Index) = rs!VarValue & ""End Sub
      

  3.   

    当然,还有一种方法,就是利用 Key_Press 事件,检测到回车键才去查询。但需要输入名字敲一个回车。Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)  If KeyAscii <> 13 Then Exit Sub  Label_Name(Index) = ""  Set rs = cn.Execute("SELECT VarValue FROM STDNAME WHERE [STDNAME]='" & Text_Name(Index) & "'")  If Not rs.EOF Then Label_Name(Index) = rs!VarValue & ""End Sub
      

  4.   

    用只读取出来rs.open sql,conn,1,1