Results 1 to 13 of 13

Thread: [RESOLVED] Loading from a database - Too slow

  1. #1

    Thread Starter
    Hyperactive Member knxrb's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    321

    Resolved [RESOLVED] Loading from a database - Too slow

    Hi guys, I've got a database that's 13,000 lines long and I'm trying to load this into a string array when the program loads but it takes approx 5-6 minutes for it to load it.

    I've got a MS Access database or an Excel file that I can load this information from, each has two rows: SVONo, Description

    This is my current MS Access code:
    Code:
            Try
                cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\products.mdb" & ";")
                cn.Open()
                cmd = New OleDbCommand("SELECT * FROM tblStock ORDER BY SVONO ASC", cn)
                dr = cmd.ExecuteReader
                Dim i As Integer = 0
                While dr.Read()
                    strProducts(i) = dr(1)
                    strDescriptions(i) = dr(2)
                    maxProducts += 1
                    i += 1
                End While
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
            dr.Close()
            cn.Close()
    Does anyone have any idea of how to make it faster?
    Or does anyone have a better way?

    I did have the idea of loading it by letting the user select the first letter and then only loading the ones that begin with that letter but I've got 4000-5000 'S' ones and it still takes about 2-3 minutes to load it

    All I want is to load the data from the database or the excel file and then put the products into 'cboProducts' and the 'cboProducts AutoCompleSourceList' and the descriptions into the 'txtDescriptions' AutoCompleteSourceList and a string array.
    Then when the user selects a product using 'cboProducts' the description will automatically be put into 'txtDescription'.

    Thanks in advance, knxrb
    Did I help you with your problem? If I did rate me by clicking here: Rate knxrb

  2. #2
    Fanatic Member manhit45's Avatar
    Join Date
    May 2009
    Location
    Ha noi - Viet Nam
    Posts
    826

    Re: Loading from a database - Too slow

    Dear

    i have finished many solution with access and excel database

    but never spend 5 - 6 miniutes to load them

    why dont you use datagridview,dataview, listbox or another control to load them into.

    you can use displaymember properties for listbox or datagridview . let try and tell us your trouble . Dear

  3. #3

    Thread Starter
    Hyperactive Member knxrb's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    321

    Re: Loading from a database - Too slow

    I've explained what my problem is and what I want it to do in my first post?

    It has to load into a combobox as this needs to be as simple to use as possible, so selecting from the combobox is easier than selecting from a datagridview, and the people this is intended for will know what to do with a combobox and it's unlikely they will know what to do with a datagridview.

    knxrb
    Did I help you with your problem? If I did rate me by clicking here: Rate knxrb

  4. #4
    Hyperactive Member su ki's Avatar
    Join Date
    Oct 2007
    Posts
    354

    Re: Loading from a database - Too slow

    hey knxrb
    why you are loading database in string array

    you may use datatable for storing data or if you want array sort of thing use list of string it will be faster

    or you may use displaymember and valuemember for directly load from database as @manhit45 also suggested
    * If my post helped you, please Rate it
    * If your problem is solved please also mark the thread resolved it is there in right top of page under thread tools
    * Why Rating is useful

  5. #5
    Fanatic Member manhit45's Avatar
    Join Date
    May 2009
    Location
    Ha noi - Viet Nam
    Posts
    826

    Re: Loading from a database - Too slow

    Do you want to load a column database to combox

    if so , i can help you.


  6. #6

    Thread Starter
    Hyperactive Member knxrb's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    321

    Re: Loading from a database - Too slow

    Exactly
    The first column needs to go into a combobox and also into the combobox AutoCompleteSource but it needs to be fast as well if that's possible

    knxrb
    Did I help you with your problem? If I did rate me by clicking here: Rate knxrb

  7. #7
    Fanatic Member manhit45's Avatar
    Join Date
    May 2009
    Location
    Ha noi - Viet Nam
    Posts
    826

    Re: Loading from a database - Too slow

    OK
    Very easy , i am using sql, you only instead sql into OLE

    Code:
    Dim objDataAdapterPT As New SqlDataAdapter("SELECT * from Kho_PT ", objConnection)
    Dim PTdataview as new dataview
    Dim PT dataset as new dataset
    
            objDataAdapterPT.Fill(PTdataset, "PT")
    
             PTdataview = New DataView(PTdataset.Tables("PT"))
    
           combox1.DataSource = PTdataview
            combox1.DisplayMember = "STT"
    Last edited by manhit45; May 6th, 2009 at 05:15 AM.

  8. #8

    Thread Starter
    Hyperactive Member knxrb's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    321

    Re: Loading from a database - Too slow

    Ah, thank you, I'll try that now
    I didn't realise that the DisplayMember bit existed :P

    knxrb
    Did I help you with your problem? If I did rate me by clicking here: Rate knxrb

  9. #9

    Thread Starter
    Hyperactive Member knxrb's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    321

    Re: Loading from a database - Too slow

    Ok, that works fine thanks and it's fast

    How would I add the AutoCompleteSource to 'cboProductCode'?

    Here's my finished code:
    Code:
            cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strProductsDatabase & ";;")
            Dim objDataAdapterPT As New OleDbDataAdapter("SELECT * FROM tblStock ", cn)
            cn.Open()
            Dim PTdataview As New DataView
            Dim PTdataset As New DataSet
            objDataAdapterPT.Fill(PTdataset, "tblStock")
            PTdataview = New DataView(PTdataset.Tables("tblStock"))
            AddData.cboProductCode.DataSource = PTdataview
            AddData.cboProductCode.DisplayMember = "SVONo"
            AddData.cboDescription.DataSource = PTdataview
            AddData.cboDescription.DisplayMember = "Description"
            cn.Close()
    knxrb
    Did I help you with your problem? If I did rate me by clicking here: Rate knxrb

  10. #10
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Loading from a database - Too slow

    Try this
    vb.net Code:
    1. Public Class Form1
    2.     Private Sub AutoCompleteCombo(ByVal MyCombo As ComboBox, ByVal KeyCodes As KeyEventArgs)
    3.         Dim strSearchText As String
    4.         Dim intIndex As Integer
    5.         Dim objFound As Object
    6.         Dim strFound As String
    7.         Dim strAddText As String
    8.  
    9.         Select Case KeyCodes.KeyCode
    10.             Case Keys.Back, Keys.Left, Keys.Right, Keys.Up, Keys.Delete, Keys.Down
    11.                 Return
    12.         End Select
    13.  
    14.         strSearchText = MyCombo.Text
    15.         intIndex = MyCombo.FindString(strSearchText)
    16.  
    17.         If intIndex >= 0 Then
    18.             objFound = MyCombo.Items(intIndex)
    19.             strFound = MyCombo.GetItemText(objFound)
    20.             strAddText = strFound.Substring(strSearchText.Length)
    21.             MyCombo.Text = strSearchText & strAddText
    22.             MyCombo.SelectionStart = strSearchText.Length
    23.             MyCombo.SelectionLength = strAddText.Length
    24.         End If
    25.  
    26.     End Sub
    27.  
    28.     Private Sub cboProductCode_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cboProductCode.KeyUp
    29.         AutoCompleteCombo(cboProductCode, e)
    30.     End Sub
    31. End Class

  11. #11

    Thread Starter
    Hyperactive Member knxrb's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    321

    Re: Loading from a database - Too slow

    WOW! Thanks Hack, it works perfectly

    knxrb
    Did I help you with your problem? If I did rate me by clicking here: Rate knxrb

  12. #12
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: [RESOLVED] Loading from a database - Too slow

    As for obtaining the data, you may be able to gain a performance increase if you adopt one of these options.
    Note, they are structured for SQL, just re do as OleDb. My guess is that you can get away from a DataSet per se, and just use a DataTable, or, just a DataReader....

  13. #13

    Thread Starter
    Hyperactive Member knxrb's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    321

    Re: [RESOLVED] Loading from a database - Too slow

    Thanks

    knxrb
    Did I help you with your problem? If I did rate me by clicking here: Rate knxrb

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width