Sqlite database and datagrid

13,751

I used the following in one of my projects :

private void UpdateDataGrid(SQLiteConnection con, string sql)
{
    DataSet dataSet = new DataSet();
    SQLiteDataAdapter dataAdapter = new SQLiteDataAdapter(sql, con);
    dataAdapter.Fill(dataSet);

    dataGrid.DataSource = dataSet.Tables[0].DefaultView;
}

Columns are generated automatically based on the query, if you want to preview all your table use the following : "SELECT * From TableName"

This worked perfectly in my winforms app, you might need to change a few things for it in WPF tho, I'm not sure.

Share:
13,751
pauliustack
Author by

pauliustack

Updated on July 20, 2022

Comments

  • pauliustack
    pauliustack almost 2 years

    I am trying to display my database(simple grades database) to wpf datagrid.Maybe someone know good example or simple code of connecting sqlite with datagrid?Also what is better:1.Manually create columns or use autogeneratecolumns? Thanks

  • Barkermn01
    Barkermn01 almost 9 years
    Why the hell is this marked as an aswer the question quite clearly says WPF and WinForms is not WPF you might need to change a few things for it in WPF tho means nothing this does not work in WPF
  • gattsbr
    gattsbr about 7 years
    In looking for an answer to this for WPF i came across the following: codereview.stackexchange.com/a/101266