Monday, September 30, 2013

Code sample to Access data using SQLite


Sample code written to access the data using SQLite.

--------------------------------------------------------------------------------------------------

        string apppath = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "AppData");

        string fullPath = Path.Combine(apppath, "test.s3db");

        SQLiteConnection.CreateFile(fullPath);

        Con = new SQLiteConnection(String.Format("Data Source={0};Version=3;", fullPath);       
       
        Con.Open();

        SQLiteCommand cmd = new SQLiteCommand(conread);
           
        string comand = "select * from tbl";
        SQLiteCommand cmd = new SQLiteCommand(cmd, Con);
        cmd.ExecuteNonQuery();
        SQLiteDataAdapter adapt = new SQLiteDataAdapter(cmd);
        DataTable dt = new DataTable("tbl");
        adapt.Fill(dt);
        dataGrid1.ItemsSource = dt.DefaultView;
        con.Close();

No comments:

Post a Comment