我不能顯示在我的GridView的「價格」單元格的值的十進制值,這裏是我的代碼:無法看到的DataGridView C#中的細胞
DataColumn idCol2 = new DataColumn();
idCol2.DataType = System.Type.GetType("System.Int32");
idCol2.ColumnName = "Id";
table.Columns.Add(idCol2);
DataColumn SKUCol2 = new DataColumn();
SKUCol2.DataType = System.Type.GetType("System.String");
SKUCol2.ColumnName = "SKU";
table.Columns.Add(SKUCol2);
DataColumn ProdNameCol2 = new DataColumn();
ProdNameCol2.DataType = System.Type.GetType("System.String");
ProdNameCol2.ColumnName = "Product Name";
table.Columns.Add(ProdNameCol2);
DataColumn DescCol2 = new DataColumn();
DescCol2.DataType = System.Type.GetType("System.String");
DescCol2.ColumnName = "Product Description";
table.Columns.Add(DescCol2);
DataColumn PriceCol2 = new DataColumn();
PriceCol2.DataType = System.Type.GetType("System.Decimal");
PriceCol2.ColumnName = "Price";
table.Columns.Add(PriceCol2);
DataColumn[] keys2 = new DataColumn[5];
keys2[0] = idCol2;
table.PrimaryKey = keys2;
LivePOS livepos = new LivePOS(clientId, clientSecret);
_products = livepos.GetProducts(apiKey, token);
foreach (var p in _products)
{
table.Rows.Add(p.Id, p.Sku, p.Name, p.Description , p.SellingPrice);
}
table.DefaultView.Sort = "Id ASC";
dataGridView1.DataSource = table;
this.dataGridView1.DefaultCellStyle.Format = "N4";
foreach (DataGridViewRow row in dataGridView1.Rows)
{
row.Cells[0].ReadOnly = false; //id
row.Cells[1].ReadOnly = true; //sku
row.Cells[2].ReadOnly = true; //name
row.Cells[3].ReadOnly = true; //description
}
請幫我:)有什麼問題在此代碼?我在Form_Load事件中創建了名爲「table」的數據表的新實例。除此「價格」欄外,所有單元格值均正確顯示。
什麼是你在DB使用的價格,給我們的樣本值的類型從_products ... – Pandian
'DECIMAL(19,4)將需要9個存儲字節 MONEY需要8個存儲字節'請驗證以及澄清什麼價格的數據類型在數據庫中定義 – MethodMan
您可以舉例說明什麼問題與預期號碼和顯示的號碼一樣? – V4Vendetta