tags:

views:

56

answers:

2

I have the following code block

SQLiteConnection cnn = new SQLiteConnection("Data Source=" + getDBPath());
cnn.Open();
SQLiteCommand mycommand = new SQLiteCommand(cnn);
string values = "'" + this.section + "','" + this.exception + "','" + this.dateTimeString + "'";
string sql = @"INSERT INTO Emails_Pending (Section,Message,Date_Time) values (" + values + ")"; 
mycommand.CommandText = sql;
mycommand.ExecuteNonQuery();
cnn.Close();

When I execute it , nothing happens, no errors are produced, but nothing gets inserted, what am I doing wrong?

Path to DB is correct! Insert statement works, tried it in a SQLLite GUI (no problems there)

Here is the SQL Snippet:

"INSERT INTO Emails_Pending (Section,Message,Date_Time) values ('Downloading Received Messages','Object reference not set to an instance of an object.','04.12.2009 11:09:49');"
A: 

How about adding Commit before Close

mycommand.Transaction.Commit();
S.Mark
Object reference not set to an instance of an object, I guess because I am not using a transaction.
JL
A: 

You should always use transactions and parameterized statements when using sqlite, else the performance will be very slow.

Read here: http://stackoverflow.com/questions/1711631/how-do-i-improve-the-performance-of-sqlite

Your approach is vulnerable to sql injection too. A message in an email can have a piece of sql in its body and your code will execute this piece of sql. You can also run into problems when the message in your string values contains a " or a ' .

tuinstoel