0
我不明白爲什麼發送參數插入功能在.net緊湊框架中工作緩慢。在.Net緊湊框架中的性能問題
Forexample2秒
cn = New SqlCeConnection(strstring)
cmd = New SqlCeCommand
Dim rs As SqlCeResultSet
cmd.Connection = cn
cmd.CommandType = CommandType.TableDirect
cn.Open()
Dim rec As SqlCeUpdatableRecord
Dim DB As New Db
Dim a As Integer = 1
Dim b As Integer = 2
For i As Integer = 0 To 1000
If i = 0 Then
cmd.CommandText = "A"
rs = cmd.ExecuteResultSet(ResultSetOptions.Updatable)
rec = rs.CreateRecord()
End If
Try
rec.SetValue(0, a)
rec.SetValue(1, b)
rs.Insert(rec
Catch ex As Exception
End Try
Next
但是,當我發送參數,a和b,在插入子,該代碼13 seconds.What確實性能降低內完成內以下代碼插入?
cn = New SqlCeConnection(strstring)
cmd = New SqlCeCommand
Dim rs As SqlCeResultSet
cmd.Connection = cn
cmd.CommandType = CommandType.TableDirect
cn.Open()
Dim rec As SqlCeUpdatableRecord
For i As Integer = 0 To 1000
If i = 0 Then
cmd.CommandText = "A"
cmd.CommandType = CommandType.TableDirect
rs = cmd.ExecuteResultSet(ResultSetOptions.Updatable)
rec = rs.CreateRecord()
End If
Try
DB.Insert(1, 2, rs, rec)
Catch ex As Exception
End Try
Next
這是DB類插入子
公共類Db的
Public Shared Sub Insert(ByVal a As Integer, ByVal b As Integer, ByRef rs As SqlCeResultSet, ByRef rec As SqlCeUpdatableRecord)
Try
rec.SetValue(0, a)
rec.SetValue(1, If(b = String.Empty, DirectCast(DBNull.Value, Object), b))
rs.Insert(rec)
Catch ex As Exception
End Try
End Sub
末級
2整數複製到堆棧? – 2009-11-02 18:53:57
不必要的嘗試/趕上? – 2009-11-02 18:55:07
打破一個分析器,看看? – 2009-11-02 18:55:56