SQL:
CREATE TABLE main.LogRecord (
Id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL ,
TimeStamp DATETIME NOT NULL ,
Type TEXT NOT NULL ,
Severity TEXT NOT NULL ,
Message TEXT NOT NULL ,
Origin TEXT NOT NULL)
INSERT INTO LogRecord
(TimeStamp, Type, Severity, Message, Origins) VALUES
(@timestamp, @type, @severity, @message, @origin)
C# Pseudo-ish Code:
SQLiteCommand command = new SQLiteCommand(INSERT_COMMAND_TEXT);
command.Parameters.AddWithValue("@paramName", object.value);
command.Connect = connectVar;
command.ExecuteNonQuery();
When ExecuteNonQuery()
runs, the value 1
is returned which according to SqliteOrg means:
SQL error or missing database
Except, no exception is thrown AND the data is inserted correctly.
Is there way to get the LAST_ERROR_MESSAGE
using System.Data.SQLite
? I've only come across ways to get the last error message for non .net APIs.
When I incorrectly insert to a column that does not exists the same error code (1) is returned BUT this time an exception is thrown with the last error message.
So if the insert is working, why is 1 being returned? Any help is greatly appreciated.
Edit: I also tried not sending the TimeStamp DateTime
in case it was a date formatting issue but the same situation occurs.
Edit: Turns out 1 is the # of rows affected and it's all in the documentation http://msdn.microsoft.com/en-us/library/system.data.idbcommand.executenonquery%28v=vs.80%29.aspx
Reread your docs. I believe ExecuteNonQuery returns the number of rows affected or -1 on an error.