Reputation: 1969
I'm messing around with SQL lite and learning it.
I got a table called People, I got some method that connect to the database and do some stuff, like show all the info.
Now I'm trying to insert some data and here it get wierd for me. I have this method:
private void ExecuteQuery(string txtQuery)
{
SetConnection();
sql_con.Open();
sql_cmd = sql_con.CreateCommand();
sql_cmd.CommandText = txtQuery;
sql_cmd.ExecuteNonQuery();
sql_con.Close();
}
and to see all the data I've got this method:
private void LoadData()
{
SetConnection();
sql_con.Open();
sql_cmd = sql_con.CreateCommand();
string CommandText = "SELECT * FROM People";
DB = new SQLiteDataAdapter(CommandText, sql_con);
DS.Reset();
DB.Fill(DS);
DT = DS.Tables[0];
dataGridView1.DataSource = DT;
sql_con.Close();
}
When I inset some data and right afther it I call the LoadData()
, I can see all the changes I made.
After I close the program, and then open it agian and call LoadData()
, I don't see the new info that I inserted before.
I got some data that I used SQL lite GUI app to insert, and I can see that data every time I call the LoadData()
method, but not mine.
Do I need to do somthing else to make sure SQL lite saves all the data?
EDIT: this is how i INSERT the data, mybee the problem is from here?
string insetCommand = "INSERT INTO People Values(2,'" + textBox1.Text + "')";
EDIT2: my connectionString Method
public static string connectionString
{
get
{
string database =
//AppDomain.CurrentDomain.BaseDirectory + "..\\..\\Database\\ImageLib.s3db";
AppDomain.CurrentDomain.BaseDirectory + "\\DataBase\\myTable2";
string connectionString =
@"Data Source=" + Path.GetFullPath(database) + ";Version=3;";
return connectionString;
}
}
Upvotes: 1
Views: 6601
Reputation: 180020
Your problem looks as if your data is stored in a temporary database.
Please check that your connectionString
is actually used (SQLite will use a temporary database if the file name is empty).
To check the database file name from inside your application, execute PRAGMA database_list
like a query and check that the third column of the result contains your file name. Example output:
> pragma database_list;
seq name file
----- ------ ----------
0 main /tmp/test.db
Upvotes: 1
Reputation: 5596
Try to execute a commit statement, i belive that SQLite needs that! You can also try to wrap it all in a transaction!
Upvotes: 0