0

The code doesn't produce an exception and seemingly runs fine. But after running it and checking the table i see that the row is not inserted. I use navicat for cheking and that's not the problem. I've double-checked the table name and field names which all correct. What's wrong?

try
{
    SQLiteConnection conn = new SQLiteConnection("Data Source=path;Version=3;FailIfMissing=True");

    conn.Open();
    String sql = "INSERT INTO sales (cust_id, date, cost, price) VALUES ('0', '" + String.Format("{0:u}", DateTime.Now.Date).Split(' ')[0] + "', '" + cost.ToString() + "', '12')";
    SQLiteCommand command = new SQLiteCommand(sql, conn);

    conn.Close();
}
catch (Exception err)
{
    MessageBox.Show(err.Message.ToString());
}
1
  • 3
    because its never executed? Commented Feb 12, 2015 at 9:41

1 Answer 1

1

add:

command.ExecuteNonQuery();

on your code:

...
SQLiteCommand command = new SQLiteCommand(sql, conn);
command.ExecuteNonQuery();

Also it is always better to use parameters on your query

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.