I have a unique situation in sqlite (vb.net), Where i am trying to update fileds within a ExecuteReader while loop.
scenario: db table columns: ID, Val1, Val2 input: have 2 arrays of characters. task:
to update ALL ROWS:
1. Read VAL1
2. Replace CHARACTERS as defined in strMapp e.g. (A->a,B->x,D->f) etc
3. UPDATE this new String to column 'Val2'
MY CODE SO FAR:
dim strMap As New Dictionary(Of String, String)
strMap.Add("A", "a")
strMap.Add("B", "x")
strMap.Add("C", "f")
strMap.Add("D", "h")
strMap.Add("E", "l")
conn1 = New SQLiteConnection("Data Source=test.s3db;Read Only=True")
conn2 = New SQLiteConnection("Data Source=test.s3db")
Dim cmd As New SQLiteCommand(conn1)
Dim cmd2 As New SQLiteCommand(conn2)
conn1.open ''read only
conn2.open ''to update
Dim ii As Integer
Dim query as String = "SELECT ID,Val1,Val2 FROM my_table"
cmd.commandText=query
Dim myReader As SQLiteDataReader
myReader = cmd.ExecuteReader
If myReader.HasRows = True Then
Do While myReader.Read()
oldStr = myReader("Val1")
newStr = oldStr
For j As Integer = 0 To newStr .Length - 1
nChar = newStr.Substring(j, 1)
If strMap.ContainsKey(nChar) Then
newStr = newStr .Replace(nChar, strMap(nChar))
End If
Next j
Qry = "UPDATE my_table set Val2='" & newStr "' WHERE ID=" & myReader("ID")
cmd2.CommandText=Qry
cmd2.ExecuteNonQuery(Qry) '''''THIS CODE GIVES ERROR: database corruption
ii = ii + 1
Loop
End If
Problem: It is giving "database corruption" error. I've marked the code where error occurs. please advise
cmd?