gpt4 book ai didi

c# - 从 SQLite View 获取 DataGrid 数据

转载 作者:行者123 更新时间:2023-12-02 13:46:13 25 4
gpt4 key购买 nike

我正在开发一个 WPF 应用程序。它有几个 TextBox 字段和一个 DataGrid。为了创建 SQLite 数据库(只有一个表),我已经这样做了......

SQLiteCommand command = new SQLiteCommand(connection);
command.CommandText = "CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,name VARCHAR(100)...

等等...现在创建 View 的查询是:

command.CommandText = "CREATE VIEW IF NOT EXISTS users_details AS SELECT name,adress...

依此类推。这工作完美,但是......我陷入了一个问题。我想将该 View “user_details”与我的 DataGrid 连接起来。任何指导或解决方案的一部分将不胜感激......

最佳答案

您需要创建另一个 SQLiteCommand从 View 中检索数据,然后将其用作 ItemsSource对于DataGrid

SQLiteCommand command = new SQLiteCommand(connection);
command.CommandText = "SELECT * FROM users_details"

SQLiteDataAdapter da = new SQLiteDataAdapter(command);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable dt = ds.Tables[0];
this.dataGrid.ItemsSource = dt.AsDataView();

关于c# - 从 SQLite View 获取 DataGrid 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31963293/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com