SQLite Exception: Error Code 20 when Saving Record

Discussion in 'Beta' started by BPak, Dec 1, 2010.

  1. BPak

    BPak Active Member Licensed User

    Trying to save a record in a database and get an error.

    Sub Process_Globals
    'These global variables will be declared once when the application starts.
       'These variables can be accessed from all modules.
       Dim SQL1 As SQL
    End Sub

    Sub Globals
    'These global variables will be redeclared each time the activity is created.
       'These variables can only be accessed from this module.
       Dim NameEd As EditText
    Dim BankEd As EditText
    Dim LoseCntEd As EditText
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
    If FirstTime = True Then
    End If
    End Sub

    Sub Activity_Resume

    End Sub

    Sub Activity_Pause (UserClosed As Boolean)
    If UserClosed Then SQL1.Close
    End Sub

    Sub CreateConnection
    If SQL1.IsInitialized = False Then
    File.DirDefaultExternal, "Metz.db"True)
    ' Create Account Table
    End If
    End Sub

    Sub SaveBtn_Click
    Dim IDs As String
    Dim Name As String
    Dim Bank As String
    Dim Lose As String

       IDs = 
       Name = NameEd.Text
       Bank = BankEd.Text
       Lose = LoseCntEd.Text
    ' save new or edit account to account dbase
       SQL1.ExecNonQuery2("INSERT INTO account VALUES(?,?,?,?)", _
    Array As String(IDs, Name, Bank, Lose))   
    End Sub
    I think it is something to do with the PRIMARY KEY.

    Is there a special way to do an Entry that uses PRIMARY KEY?

    Attached Files:

  2. Erel

    Erel Administrator Staff Member Licensed User

    SQL1.ExecNonQuery2("INSERT INTO account VALUES(?,?,?)", _
    Array As String(Name, Bank, Lose))
  3. klaus

    klaus Expert Licensed User

    Unfortunately this doesn't work.
    SQL1.ExecNonQuery2("INSERT INTO account VALUES(?,?,?)", _
    Array As String(Name, Bank, Lose))
    But this one does.
    SQL1.ExecNonQuery2("INSERT INTO account VALUES(NULL,?,?,?)", _
    Array As String(Name, Bank, Lose))
    Best regards.
  4. BPak

    BPak Active Member Licensed User


    I came up with a work around but the way Klaus has it would be safer to use.

    ' work around, does work
       str1 = "INSERT INTO account VALUES (Null, '" & NameEd.Text & "', " & BankEd.Text & ", " & LoseCntEd.Text & ")"
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice