我遇到了 C# WPF 的问题,我想在 WPF DataGrid 控件中显示一些 SQLite 数据表。我们将产品的价格存储为 NUMERIC(但也尝试将其存储为 REAL,但效果完全相同),但在数据网格控件中,它显示为整数,尽管在 SQLite DB 浏览器上它显示正确的十进制值。下面是我们将数据填充到 DataGrid 中的代码:
ProductsDataGrid.ItemsSource = db.GetDataSet("*", "products").Tables[0].AsDataView();
GetDataSet 方法如下所示:
public DataSet GetDataSet(string columns, string table, string trailingCommands = "")
{
var sqlcmd = string.Format("select {0} from {1} {2}", columns, table, trailingCommands);
Utility.Log.Info(sqlcmd);
DataSet dataSet = new DataSet();
SQLiteDataAdapter dataAdapter = new SQLiteDataAdapter(sqlcmd, this.dbconn);
dataAdapter.Fill(dataSet);
return dataSet;
}
简洁版本:
该程序在 SQLite DB 的数据网格中将十进制数字显示为 int
检查你的 SQLite 小数分隔符,可能就是这样。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)