wpf Sqlite 数据库和数据网格
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19617368/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Sqlite database and datagrid
提问by pauliustack
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
我正在尝试将我的数据库(简单成绩数据库)显示到 wpf 数据网格。也许有人知道将 sqlite 与数据网格连接的好例子或简单代码?还有什么更好:1.手动创建列或使用自动生成列?谢谢
回答by Marc
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"
列是根据查询自动生成的,如果要预览所有表,请使用以下命令:“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.
这在我的 winforms 应用程序中运行良好,您可能需要在 WPF 中为它更改一些内容,我不确定。
回答by kmatyaszek
Here is video tutorial SQLite database connection with WPF C#:
这是使用 WPF C# 连接 SQLite 数据库的视频教程:
C# WPF Tutorial 3- SQLite database connection with WPF C# PART- 1/2
C# WPF 教程 3- SQLite 数据库连接与 WPF C# PART- 1/2
C# WPF Tutorial 4- SQLite database connection with WPF C# PART- 2/2
C# WPF 教程 4- SQLite 数据库连接与 WPF C# PART- 2/2
Look also this tutorial:
也看看这个教程:

