I have written a code which does the thing as the title says. The problem is, the whole process took 10 minutes just for 1000 records. Here is the code:(Written in vb.net 3.5 and sql server ce)
MyConnection.Open()
Dim count As UInt32
cmnd = New SqlCeCommand(sqlstring, MyConnection)
cmnd.CommandType = CommandType.TableDirect
myreader = cmnd.ExecuteResultSet(ResultSetOptions.Scrollable Or ResultSetOptions.Updatable)
myreader.ReadLast()
myreader.Read()
Dim i As UInt16
Do Until _TableItem(count) Is Nothing
record = myreader.CreateRecord()
For i = 0 To 20
record.SetString(i, _TableItem(count + i).value())
Next
myreader.Insert(record)
count += 21
Loop
MyConnection.Close()
How can I optimize this code for better performance?
Thanks.
Well, though I have figured it out myself, I am answering this question regarding to the others stuck in the same problem.
The solution is, actually, to use a for each and a select case(c# switch) statement instead of do and for loops. The code would look like:
The code change alone has saved me whole 7 minutes of time. Note that the process takes a long time by default because the records inside the items are very large.