samedi 2 janvier 2016

sqlitexception logic error or missing database no such table:nam

I am very new to sqlite to be used in C#. So I created the db in the bin folder. I create a class below.

class myCon
    {
        public SQLiteConnection GetConnection()
        {
            string str = @"Data Source=gf.sqlite3";

            SQLiteConnection con = new SQLiteConnection(str);
            con.Open();
            return con;
        }
    }

Then I call it as below to test my insert

 try
                {
                    myCon getMyCon1 = new myCon();
                    SQLiteConnection con = getMyCon1.GetConnection();


                    string sql = "insert into nam (Id, test1) values ('3000')";
                    SQLiteCommand command = new SQLiteCommand(sql, con);
                    command.ExecuteNonQuery();

                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }

I have confirm using the gui browser the table and db is there. I just cant figure out what is wrong?

Aucun commentaire:

Enregistrer un commentaire