C#WPF DataGrid不显示SQLite 3数据库的十进制数 [英] C# WPF DataGrid doesn't show decimal from SQLite 3 database

查看:489
本文介绍了C#WPF DataGrid不显示SQLite 3数据库的十进制数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个C#WPF的问题,我想在WPF DataGrid控件中显示一些SQLite数据表。我们将产品的价格存储为NUMERIC(但是也是以REAL为单位),但是在datagrid控件中显示为整数,尽管在SQLite DB浏览器上显示了正确的十进制值。以下是我们将数据填入DataGrid的代码:

  ProductsDataGrid.ItemsSource = db.GetDataSet(* ,products)。表[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中的datagrid

解决方案

检查您的SQLite小数点分隔符,可以这样。


I ran into an issue with C# WPF, where I want to show some SQLite data table in WPF DataGrid control. We store the price of a product as a NUMERIC (but also tried as REAL, but it does the very same), but in the datagrid control it is shown as integer, despite on the SQLite DB Browser it shows the proper decimal value. Here is the code with which we fill in the data into the DataGrid:

ProductsDataGrid.ItemsSource = db.GetDataSet("*", "products").Tables[0].AsDataView();

and the GetDataSet method looks like this:

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;
}

Short version: The program shows decimal numbers as int in a datagrid from SQLite DB

解决方案

Check your SQLite decimal separator character, that's could be it.

这篇关于C#WPF DataGrid不显示SQLite 3数据库的十进制数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆