mardi 27 octobre 2015

C# can not open sqlite database

I created a database file with Sqlite and now I can not load this file into dataset. This is what I have at the moment. Is this a proper way of doing things?

                try
                {
                    SQLiteCommand cmd;
                    DataTable dt = new DataTable();
                    SQLiteConnection sql_con;
                    SQLiteDataAdapter DB;

                    sql_con = new SQLiteConnection("Data Source = C:\\Users\\arnas\\Documents\\Visual Studio 2013\\Projects\\Trade Journal V1\\Trade Journal V1\\test.db");

                    sql_con.Open();
                    cmd = sql_con.CreateCommand();
                    cmd.CommandText = "select *  from tbl1;";
                    DB = new SQLiteDataAdapter(cmd);
                    DB.Fill(dt);
                    dataGridView1.DataSource = dt;
                }
                catch(Exception Ex)
                {
                    MessageBox.Show(Ex.Message);
                }

Aucun commentaire:

Enregistrer un commentaire