我有一个代码,用于从select SQL语句创建数据表(在内存中)。但是我意识到这个数据表在程序期间填充而不是作为事务comit语句的结果,它完成了工作,但速度很慢。我做错了什么?
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
答案 0 :(得分:1)
交易防止其他用户(即连接)所做的更改;您自己的应用程序所做的任何更改都会立即显示出来。
因此,对于内存数据库,除非您需要回滚,否则事务无用。