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.
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" fieldCode: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
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.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()
thanks in advance.




Reply With Quote