Results 1 to 4 of 4

Thread: Time Issue

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Location
    Australia
    Posts
    73

    Time Issue

    Hi There.

    I am having an issue of time when connecting to an access database with vb.net.

    I open the DB, select the RS and then populate a list view with the records from the RS. This whole proccess takes about 10 seconds. When I used to do this from VB 6 it took less the 1 second to do.

    Is this normal? Do I have to live with it? Is my code wrong?

    Following is my code:

    Dim db As ADODB.Connection
    Dim rs As ADODB.Recordset
    db = New ADODB.Connection()
    db.CursorLocation = ADODB.CursorLocationEnum.adUseClient
    db.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= '" & currentDir & "';Persist Security Info=False;")
    rs = New ADODB.Recordset()
    rs = db.Execute("Select id, travelgroup, name,phone1,fax,email from agents")
    Dim itmX As ListViewItem
    While Not rs.EOF
    If Not IsDBNull(rs.Fields(1).Value) Then
    itmX = lstAgents.Items.Add(CStr(rs.Fields(1).Value))
    itmX.Tag = CStr(rs.Fields(0).Value)
    Else
    GoTo nextItem
    End If
    If Not IsDBNull(rs.Fields(2).Value) Then
    itmX.SubItems.Add(rs.Fields(2).Value)
    End If
    If Not IsDBNull(rs.Fields(3).Value) Then
    itmX.SubItems.Add(rs.Fields(3).Value)
    End If
    If Not IsDBNull(rs.Fields(4).Value) Then
    itmX.SubItems.Add(rs.Fields(4).Value)
    End If
    If Not IsDBNull(rs.Fields(5).Value) Then
    itmX.SubItems.Add(rs.Fields(5).Value)
    End If
    nextitem:
    rs.MoveNext()
    End While
    db.close()
    rs = Nothing

    Any ideas?

    Thanx in advance
    Hugh Rees
    SERTEV Technologies
    (07) 3375 9806
    0410 585 754
    WWW.SERTEV.COM

  2. #2
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188
    Well all that checking for Nulls is time waisting!

    Why not:

    1) Not allow Nulls in your database! OR
    2) Use SELECT ... CASE instead of if...then!


    Also that rs.eof loop is a slow way of doing it!

    b

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Location
    Australia
    Posts
    73
    How can you do it without using an rs.eof?
    Hugh Rees
    SERTEV Technologies
    (07) 3375 9806
    0410 585 754
    WWW.SERTEV.COM

  4. #4
    Fanatic Member Gaffer's Avatar
    Join Date
    Nov 2000
    Location
    London
    Posts
    828
    Well tehre's two things about that statement that slows things down:

    rs.EOF has to be checked every pass through the loop. So if only there was a way of determining how many records there are in your recordset, and using a FOR...NEXT loop...





    Basically put you Recordcount into a variable. Then:
    VB Code:
    1. For i = 0 to iRec  'wher iRec is you recordcount
    2.  
    3. Next i

    Also, avoid using WHILE if you can - again the program has to keep checking if that WHILE criteria is true for each loop.

    It'll save you time, but I suspect you IsDBNull function, along with Beacon's suggestions are more at fault...




    ...oh and I don't know how essntial that GOTO statement is, but I'd try and lose it if you can...

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