Hello peeps. I have recently been learning to program in .net and seem to be having speed issues when writing to databases. The code below takes ages to go through 59792 records and write them.
Now it all seems to slow down on the update method on the dataadaptor object. Is there anything I can do to speed it up? It seems to get slower and slower as it chugs through all the records to write so I dont know if its trying to update all the details at the same time. I only need it to write one at a time though.
Any advice would be appreciatedCode:Dim Adaptor As New OleDbDataAdapter Dim Command As New OleDbCommand Dim Records As New DataSet Dim Builder As OleDbCommandBuilder Dim I As Integer Dim Row As DataRow Dim Update As Integer 'Prepare command object Command.CommandText = "SELECT * FROM [Music]" Command.Connection = DB 'Setup the adaptor Adaptor.SelectCommand = Command Builder = New OleDbCommandBuilder(Adaptor) Builder.QuotePrefix = "[" Builder.QuoteSuffix = "]" Adaptor.Fill(Records, "Music") PB.Value = 0 PB.Maximum = 100 For I = 1 To UBound(Music) Row = Records.Tables("Music").NewRow() With Music(I) Row("TrackId") = .ID Row("Filename") = .Filename Row("Bitmap") = .Bitmap Row("Artist") = .Artist Row("Title") = .Title Row("Year") = .Year 'I stripped a load out to protect my data from the forum. There are about another '10 entries missing here End With Records.Tables("Music").Rows.Add(Row) 'Update Adaptor.Update(Records, "Music")'It slows down on every call here If I > Update Then 'This is an attempt to speed it up by reducing the doevents calls 'Update The progress bar PB.Value = (100 / UBound(Music)) * I Application.DoEvents() Update = Update + 100 End If Next Adaptor = Nothing Command = Nothing Records = Nothing Builder = Nothing End Sub![]()




Reply With Quote