prepared statement

Hello,
Can anyone tell me what is wrong here. I am getting a Syntax error with the prepared statement


  Dim db As New SQLiteDatabase
   Dim ps As SQLitePreparedStatement
  
  db.DatabaseFile = mod_SQLite.mod_Schema_Control.UTIL_GET_DB_File_Location
  
  If db.Connect Then
    ' Prepare the Statement
    //ps = SQLitePreparedStatement(db.Prepare(SET_Employee))
    
    ps = SQLitePreparedStatement(db.Prepare(("INSERT INTO Credentials (Company_Name, Database_Server, Database_Name, User_iD, Password) Values (?, ?, ?, ?, ?)"))
    
    'Bind the parameters
    ps.BindType(0, SQLitePreparedStatement.SQLITE_TEXT)
    ps.BindType(1, SQLitePreparedStatement.SQLITE_TEXT)
    ps.BindType(2, SQLitePreparedStatement.SQLITE_TEXT)
    ps.BindType(3, SQLitePreparedStatement.SQLITE_TEXT)
    ps.BindType(4, SQLitePreparedStatement.SQLITE_TEXT)
    
    ps.Bind(0, CustomerName)
    ps.Bind(1,DatabaseServer)
    ps.Bind(2, DatabaseName)
    ps.Bind(3, userid)
    ps.Bind(4, password)
    
    ps.SQLExecute
    
    If db.Error Then MsgBox Str(db.ErrorCode) + " - " + db.ErrorMessage
    
    db.Close
  Else
    // Couldn't Connect to the Database
    MsgBox Str(db.ErrorCode) + " - " + db.ErrorMessage
  End If
  

Think it should be:

ps = SQLitePreparedStatement(db.Prepare("INSERT INTO Credentials (Company_Name, Database_Server, Database_Name, User_iD, Password) Values (?, ?, ?, ?, ?)")

You are missing a parenthesis at the end (or there are too many right after db.prepare).

Also, you don’t need to cast the prepared statement:

ps = db.Prepare("INSERT INTO Credentials (Company_Name, Database_Server, Database_Name, User_iD, Password) Values (?, ?, ?, ?, ?)")

That should work.

You can even go the other way and Dim ps As PreparedSQLStatement, the super class for all prepared statements. If you decide to switch to a different database engine, this won’t have to change (although you’d still have to change or remove the BindType statements).

Thanks alll… I am having this issue as well…

Not sure of the string to use here

ps = SQLitePreparedStatement(db.Prepare(“UPDATE Credentials SET Company_Name = ?, Database_Server = ?, Database_Name = ?, User_id = ?, password = ? WHERE id = ?”)

Any ideas why its not working

Sorry for haste. I found it . no closing )

Thanks

Chris

[quote=85421:@Chris Timm]Thanks alll… I am having this issue as well…

Not sure of the string to use here

ps = SQLitePreparedStatement(db.Prepare(“UPDATE Credentials SET Company_Name = ?, Database_Server = ?, Database_Name = ?, User_id = ?, password = ? WHERE id = ?”)

Any ideas why its not working[/quote]

I would define a lstr which the string for the UPDATE and then use the lstr in the db.prepare