我想用 SQL 选择语句的结果填充数据表,但使用事务。我使用事务的原因是因为我有一个名称列表(作为数据表),并且我想遍历名称列表并选择名称 = 列表中名称的数据库行。数据库中有 500,000 个名称,我只想检索相关行。我有该过程的代码,因为我认为它应该看起来像(未经测试)但我不知道如何将数据放入数据表中......所以我错过了我声明数据表和该表的“填充”的东西,有人可以帮忙吗?或者建议我如何在不单独查找每个名称的情况下从数据库中获取信息。
Using connection As New SQLite.SQLiteConnection(R2WconectionString)
connection.Open()
Dim sqliteTran As SQLite.SQLiteTransaction = connection.BeginTransaction()
Try
oMainQueryR = "SELECT NameID, Address, Ocupation FROM Employees Where Name= :Name"
Dim cmdSQLite As SQLite.SQLiteCommand = connection.CreateCommand()
With cmdSQLite
.CommandType = CommandType.Text
.CommandText = oMainQueryR
.Parameters.Add(":Name", SqlDbType.VarChar)
End With
'Prevent duplicate selects by using a dictionary
Dim NameInalready As New Dictionary(Of String, String)
For Each row As DataRow In TheLIST.Rows
If NameInalready.ContainsKey(row.Item("Name")) Then
Else
NameInalready.Add(row.Item("Name"), "")
cmdSQLite.Parameters(":Name").Value = row.Item("Name")
cmdSQLite.ExecuteNonQuery()
End If
Next
sqliteTran.Commit()
Catch ex As Exception
End Try
End Using