我在这里遇到问题,但我看不出哪里出错了。
问题是我在插入过程中插入了一个有效的整数值,但是当我检索该值时,我在这一行中得到一个 DBNull 异常:
iTestValue = rTest("myscore")
完整代码如下:
Dim nCn As SQLiteConnection
ncn = New SQLiteConnection("Data Source=:memory:")
ncn.Open()
Dim cmdCreate1 As New SQLiteCommand(nCn)
cmdCreate1.CommandText = "CREATE TABLE mytable (mytext TEXT,myscore INTEGER)"
cmdCreate1.ExecuteNonQuery()
cmdCreate1.CommandText = "CREATE INDEX idx_mytable_myscore ON mytable (myscore)"
cmdCreate1.ExecuteNonQuery()
Dim nTA As SQLiteTransaction
nTA = nCn.BeginTransaction
Dim nCmdIns As New SQLiteCommand("INSERT INTO mytable (mytext,myscore) VALUES (?,?)", nCn)
Dim l&
For l = 1 To UBound(uNPhones)
nCmdIns.Parameters.Clear()
nCmdIns.Parameters.Add(ExpandCat(uNPhones(l).Text), DbType.String)
nCmdIns.Parameters.Add(uNPhones(l).Score, DbType.Int32)
nCmdIns.ExecuteNonQuery()
Application.DoEvents()
Next l
nTA.Commit()
Dim nSelTest As New SQLiteCommand("SELECT * FROM mytable", nCn)
Dim rTest As SQLiteDataReader
rTest = nSelTest.ExecuteReader
Dim iCountTest As Integer
iCountTest = 0
Do While rTest.Read
Dim iTestValue As Integer
iTestValue = rTest("myscore")
Dim sTestValue As String
sTestValue = rTest("mytext")
iCountTest += 1
Loop