从Access数据库读取数据并添加到combox非常慢

时间:2017-07-17 16:52:31

标签: database vb.net performance ms-access access-vba

所以我一直试图从一个大型访问数据库中读取,而我想要读取的表包含近20000个条目,所有这些都是在combox中需要的。通过一些测试,我发现该程序运行的时间越长,速度越慢。前5000个几乎立即添加,但接下来的5000个增量呈指数增长。总而言之,加载整个过程需要大约5分钟。我错过了一些可以提高效率的东西吗?我已经使用下面的功能iam。它在Vb.net

       Private Sub chkBoxPurchasedPart_CheckedChanged(sender As Object, e As EventArgs) Handles chkBoxPurchasedPart.CheckedChanged
        If (chkBoxPurchasedPart.Checked) Then
            chkBoxRawMaterial.Checked = False
            chkBoxSkipMaterialSelection.Checked = False
            MaterialButton.Enabled = True
            comboxMaterial.Sorted = True

            comboxMaterialHdn.Text = "AS SUPPLIED"
            comboxMaterialHdn.Enabled = False


            Dim cn As OleDbConnection
            Dim cmd As OleDbCommand
            Dim dr As OleDbDataReader
            Dim oConnect, oQuery As String
            oConnect = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Y:\eng\ENG_ACCESS_DATABASES\VisibPartAttributes.mdb"
            oQuery = "SELECT * FROM VISIB_PARTMASTER_LOCAL WHERE PRODUCT_LINE LIKE '%PUR%' OR PRODUCT_LINE LIKE '%NOSTD%' AND PARTDESCR NOT LIKE '%OBSOLETE%'"

            Try
                cn.Open()
            Catch ex As Exception
            Finally
                cn = New OleDbConnection(oConnect)
                cn.Open()
            End Try

            cmd = New OleDbCommand(oQuery, cn)
            dr = cmd.ExecuteReader


            comboxMaterial.Items.Add("- - OTHER - -")

            While dr.Read()
                comboxMaterial.Items.Add(dr(0))
            End While

            dr.Close()
            cn.Close()

            Try
                Dim s As Session = Session.GetSession()
                Dim dispPart As Part = s.Parts.Display()
                Dim c As NXOpen.Assemblies.Component = dispPart.ComponentAssembly.RootComponent

                Dim children As NXOpen.Assemblies.Component() = c.GetChildren()

                Dim childMaterial As String = Nothing

                For Each child As NXOpen.Assemblies.Component In children
                    childMaterial = child.GetStringAttribute("STACKTECK_PARTN")
                    If (childMaterial.Length > 5 Or child.Name.StartsWith("PUR")) Then
                        comboxMaterial.Text = childMaterial
                    End If
                Next

            Catch ex As Exception

            End Try

        ElseIf (chkBoxPurchasedPart.Checked = False) Then

            comboxMaterialHdn.Text = ""
            comboxMaterialHdn.Enabled = True


            txtBoxDiameter.Enabled = True

            txtBoxRoundLength.Enabled = True

            txtBoxInnerDiameter.Enabled = True

            txtBoxLength.Enabled = True

            txtBoxWidth.Enabled = True

            txtBoxThickness.Enabled = True

            MaterialButton.Enabled = False
            txtBoxVisMaterial.Text = ""
            txtBoxVisMaterialDescription.Text = ""
            txtBoxEachQuantity.Text = ""
            txtBoxTotalQuantity.Text = ""
            txtBoxUnitOfMeasure.Text = ""
            comboxMaterial.Sorted = False

            comboxMaterial.Items.Clear()
            comboxMaterial.Text = ""
        End If
    End Sub

2 个答案:

答案 0 :(得分:0)

对于将来遇到类似问题的人来说,组合框不是问题所在,之前的设计师将AutoCompleteMode设置为建议并追加,这会减慢整个过程。禁用它,你的程序应该加快。

答案 1 :(得分:0)

我只会在输入前3个或4个字符后加载组合框记录。这应该会大大减少返回的记录数量,并且仍然允许自动完成功能正常工作。

此主题包含的代码可以帮助您:get 65K records only listed in combo box from a table of 155K records