c# - sqllite dosnt save data i inserted

Posted by samy on Stack Overflow See other posts from Stack Overflow or by samy
Published on 2012-09-15T15:16:27Z Indexed on 2012/09/15 15:37 UTC
Read the original article Hit count: 130

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about c#

Related posts about winforms