Results 1 to 8 of 8

Thread: 2 ways of reading all records. Which one is best and why?

Threaded View

  1. #1

    Thread Starter
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Question 2 ways of reading all records. Which one is best and why?

    Hello, I have come up with this 2 methods of reading all records on a database table. Both work nice but I would like your expert opinion on which delivers best performance and why.

    We are reading table "DATA" and filling an array called lstData with the contents of the "Data" field.

    1) Method one is using the bindingsourse to go through all the records.

    Code:
    Me.DATATableAdapter.Connection.ConnectionString = strCmdString
    Me.DATATableAdapter.Fill(Me.Data_DatabaseDataSet.DATA)
    
    If DATABindingSource.Count > 0 Then
           For intCounter = 0 To DATABindingSource.Count - 1
                  lstData.Add(DATABindingSource.Item(intCounter)("Data"))
           Next
    End If
    2) Second methd is using a SQL statement in a connection string and a reader to do the same thing. I am not including the declaration of variables. Note: the first field in the table (field 0) is the "Data" field

    Code:
     conn = New SqlConnection(strCmdString)
     strSql = "select * from DATA"
     cmd = New SqlCommand(strSql, conn)
     conn.Open()
     rdr = cmd.ExecuteReader
    
          While rdr.Read
              strTemp = rdr.GetValue(0).ToString
              lstData.Add(strTemp)
          End While
    
     conn.Close()
    My guess is that the first method, while simpler to the eye could use more overhead. What I really would like to know is if the second method really delivers better performance and if it is worth doing all the manual SQL queries.

    thanks in advance.
    Last edited by kaliman79912; Oct 17th, 2010 at 12:38 PM.

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