'==============================================
db = new SQLiteDatabase
Dim f as FolderItem
f=New FolderItem(“C:\Projects\Xojo\Employees\ewDB.sqlite”)
db.DatabaseFile=f
'=============================================
'============== CONNECTION =====================
if db.Connect then
msgbox (“Connection”)
else
msgbox (“Not Connection”)
end if
'========================================
Tengo estas instrucciones para insert un regsitro en la tabla employees
me da un error como NO SUCH TABLE: NEW.EMPLOYEES.
Dim SQLINSERT As String
db.SQLExecute(“BEGIN TRANSACTION”)
sqlinsert=“insert into NEWDB.Employees (‘firstn’,‘lastn’) VALUES (‘uno’,‘dos’);”
db.SQLExecute (sqlinsert)
if db.Connect then
msgbox "The connection is already "
else
end if
If db.Error then
MsgBox("Error: " + db.ErrorMessage)
db.Rollback
Else
db.Commit
End If
alguien me podria ayudar… gracias
sqlinsert="insert into Employees ('firstn','lastn') VALUES ('uno','dos');"
With SQLite you shouldn’t include the name of the database unless you are referring to an attached one.
I have screen with two fields firstn.text and lastn.text
for firstn.text = George and lastn.text = Power
sqlinsert=“insert into Employees (‘firstn’,‘lastn’) VALUES (‘firstn.text’,‘lastn.text’);”
when I check the table the table got first.text instead George
What is way to save this record ?
You should use a prepared statement, but to fix your problem now
sqlinsert="insert into Employees ('firstn','lastn') VALUES ('" + firstn.text + "','" + lastn.text + "');"
This is the equivalent of
sqlinsert="insert into Employees ('firstn','lastn') VALUES ('"
sqlinsert = sqlinsert + firstn.text
sqlinsert = sqlinsert + "','"
sqlinsert = sqlinsert + lastn.text
sqlinsert = sqlinsert + "');"
You can see you need to concatenate the strings.
To be safe and use prepared statements you would use
Dim ps As PreparedSQLStatement
ps = db.Prepare("INSERT INTO employees (firstn, lastn) VALUES (?, ?);")
ps.BindType(0, SQLitePreparedStatement.SQLITE_TEXT)
ps.Bind(0, firstn.text)
ps.BindType(1, SQLitePreparedStatement.SQLITE_TEXT)
ps.Bind(1, lastn.text)
ps.SQLExecute
Hi Wayne,
Thanks for your help