Question

A question about filling an OleDbDataAdapter.

I have:

Dim cmd As OleDbCommand = New OleDbCommand(myQuery), myConnection)
Dim da As OleDbDataAdapter = New OleDbDataAdapter()
Dim dtDonnees As DataTable = New DataTable()
da.Fill(dtDonnees)

Filling takes too much time.
For 20 lines it takes 20 seconds.
And for 130 000 it takes a little more (but not 130 000 sec).
But 20 seconds is too much anyway.

Why does it take so much time?


Question part 2: can I skip fill?

I mean, after filling the datatable, I do a for each row of datatable and cast into an entities:

Dim returnList As New List(Of myObject)(dtDonnees.Rows.Count)
For Each rowDonnee As DataRow In dtDonnees.Rows
   returnList.Add(New myObject(rowDonnee))'set every data of the row into my new object
Next

Can I pass each row of OleDbDataAdapter?

Was it helpful?

Solution

If you want to try, you could skip the DataAdapter fill with this method (assuming that the DataTable is not needed). Not sure that you could gain much in performance.

Dim cmd As OleDbCommand = New OleDbCommand(myQuery, myConnection) 
Dim reader As OleDbDataReader = cmd.ExecuteReader()
while reader.Read()
   returnList.Add(New myObject(reader))
end while  

of course, in the constructor of your obiect, you should read the data and set the internal state of your object

Public Class myObject

   Dim myData As String
   ' other internal var to keep state of this object instance

   Public Sub New(ByVal reader as OleDbDataReader)
       myData = reader.GetString(0)
       ' read and initialize other internal data.
   End Sub
End Class
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top