问题
I have a windows form app with a DataGridView
populated by a TableAdapter
. I'm using the Fill
method to update the data for the UI in a looping Async
sub like so.
Private Async Sub updateUI()
Dim sw As New Stopwatch
While True
Await Task.Delay(3000)
sw.Restart()
'myTableAdapter.Fill(getDataWithMySQL())
'myTableAdapter.Fill(myDataSet.myTable)
myTableAdapter.Fill(myDataSet.myStoredProc)
logger.Debug(sw.ElapsedMilliseconds)
End While
End Sub
The getDataWithMySQL
function is as follows:
Private Function getDataWithMySQL() As myDataSet.myDataTable
Dim connStr As String = My.Settings.myConnectionString
Dim sql As String = "SELECT ... LEFT JOIN ..."
Dim dt As New myDataSet.myDataTable
Using conn As New MySqlConnection(connStr)
Using cmd As New MySqlCommand()
With cmd
.CommandText = sql
.Connection = conn
End With
Try
conn.Open()
Dim sqladapter As New MySqlDataAdapter(cmd)
sqladapter.Fill(dt)
Catch ex As MySqlException
MsgBox(ex.Message)
End Try
End Using
End Using
Return dt
End Function
myDataSet.myTable
is the same as myDataSet.myStoredProc
except it is created by joining tables in the DataSet designer. Obviously myDataSet.myStoredProc
is the same query in a stored procedure in the source database.
So benchmarking the Fill
with each method using a Stopwatch
I get the following results:
myDataSet.myStoredProc
~750msmyDataSet.myTable
~550msgetDataWithMySQL()
<10ms
So my question is, what is causing the performance difference here? I'd prefer to use myDataSet.myTable
or myDataSet.myStoredProc
but I don't know if it is possible to optimise them in some way so as to match the performance of getDataWithMySQL()
.
来源:https://stackoverflow.com/questions/28358425/why-the-performance-difference-between-tableadapter-fill-data-sources