[英]Get DataGrid data from SQLite view
我正在处理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)...
依此类推...现在创建视图的查询是:
command.CommandText = "CREATE VIEW IF NOT EXISTS users_details AS SELECT name,adress...
依此类推。 这可以完美工作,但是...我陷入了一个问题。 我想将该视图“ user_details”与我的DataGrid
。 任何指导或解决方案的一部分将不胜感激...
您将需要创建另一个SQLiteCommand
来从视图中检索数据,然后将其用作DataGrid
的ItemsSource
。
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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.