Reputation: 1390
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());
}
Upvotes: 0
Views: 225
Reputation: 14389
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
Upvotes: 1