我有一个从 select SQL 语句创建数据表(在内存中)的代码。但是我意识到这个数据表是在过程中填充的,而不是由于事务提交语句的结果,它可以完成这项工作,但速度很慢。我究竟做错了什么 ?
Inalready.Clear() 'clears a dictionary
Using connection As New SQLite.SQLiteConnection(conectionString)
connection.Open()
Dim sqliteTran As SQLite.SQLiteTransaction = connection.BeginTransaction()
Try
oMainQueryR = "SELECT * FROM detailstable Where name= :name AND Breed= :Breed"
Dim cmdSQLite As SQLite.SQLiteCommand = connection.CreateCommand()
Dim oAdapter As New SQLite.SQLiteDataAdapter(cmdSQLite)
With cmdSQLite
.CommandType = CommandType.Text
.CommandText = oMainQueryR
.Parameters.Add(":name", SqlDbType.VarChar)
.Parameters.Add(":Breed", SqlDbType.VarChar)
End With
Dim c As Long = 0
For Each row As DataRow In list.Rows 'this is the list with 500 names
If Inalready.ContainsKey(row.Item("name")) Then
Else
c = c + 1
Form1.TextBox1.Text = " Fill .... " & c
Application.DoEvents()
Inalready.Add(row.Item("name"), row.Item("Breed"))
cmdSQLite.Parameters(":name").Value = row.Item("name")
cmdSQLite.Parameters(":Breed").Value = row.Item("Breed")
oAdapter.Fill(newdetailstable)
End If
Next
oAdapter.FillSchema(newdetailstable, SchemaType.Source)
Dim z = newdetailstable.Rows.Count
'此时newdetailstable已经填满了,我什至还没有提交交易
' sqliteTran.Commit()
Catch ex As Exception
End Try
End Using