我想用SQL select语句的结果填充数据表,但使用事务。我使用事务的原因是因为我有一个名称列表(作为数据表),我想遍历名称列表并选择名称=列表中的名称的数据库行。数据库中有500,000个名字,我只想要检索相关的行。我有这个程序的代码,因为我认为它应该看起来像(未测试),但我不知道如何将数据放入数据表....所以我错过了我声明数据表的地方和该表的'填充' ,有人可以帮忙吗?或者建议我怎样才能从batabase中获取信息,而无需单独查看每个名称。使用SQL'选择'在数据表中填充数据表
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
列表中可能有大约500个名字,我应该说我的appology,我也认为Transactions也是加快多个数据库查询的好方法。这是我第三天交易,所以我在这方面相当绿色。 – user1500403 2012-08-01 01:27:50
谢谢你,这些添加使整个代码完美工作! – user1500403 2012-08-01 01:58:33
我想问一下如何实现阅读器解决方案?尽管上述情况在极端情况下可用,但数据表太大而无法存储在内存中,因此读者可能是一个很好的解决方案,但是如何在循环名称的同时实现读者的读写? – user1500403 2012-08-31 00:57:04