0

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');"
demongolem
  • 9,474
  • 36
  • 90
  • 105
JL.
  • 78,954
  • 126
  • 311
  • 459

2 Answers2

0

How about adding Commit before Close

mycommand.Transaction.Commit();
YOU
  • 120,166
  • 34
  • 186
  • 219
  • 1
    Object reference not set to an instance of an object, I guess because I am not using a transaction. – JL. Dec 04 '09 at 10:04
0

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

Read here: Improve INSERT-per-second 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 ' .

Community
  • 1
  • 1
tuinstoel
  • 7,248
  • 27
  • 27