dimanche 24 janvier 2016

SQLite update query works in console, not in .Net

I am using an SQLite database in my application. For some reason the query:

    UPDATE USERS SET PASSWORD = 'test' WHERE USERNAME = 'Admin'

works in console (updates the PASSWORD field), but when I run it via code:

Dim exec As String = "UPDATE USERS SET PASSWORD = '" & password & "' WHERE USERNAME = '" & username & "'"
Dim returnCode As [Boolean] = True
Try
    ExecuteNonQuery(exec)
Catch
    returnCode = False
End Try
Return returnCode

The function always returns false, and the database is not updated. Here is the ExecuteNonQuery method:

Public Shared Function ExecuteNonQuery(sql As String) As Integer
    Dim cnn As New SQLiteConnection(dbConnection)
    cnn.Open()
    Dim mycommand As New SQLiteCommand(cnn)
    mycommand.CommandText = sql
    Dim rowsUpdated As Integer = mycommand.ExecuteNonQuery()
    cnn.Close()
    Return rowsUpdated
End Function

What am I doing wrong here? My code for creating a new row works fine, but updating doesn't.

Yes, I am aware this is unsafe, I originally had a bunch more safety checks, but I need to at least get it to work before doing so.

Aucun commentaire:

Enregistrer un commentaire