【发布时间】:2016-08-29 19:13:27
【问题描述】:
我正在尝试将 datagridview 用于购物篮。我已经让它显示客户的购物篮,但我希望它显示价格列的货币,但我也有一个数量列,所以如果我将默认样式设置为货币,那么它会将两列都更改为货币格式。
我希望能够将货币格式添加到价格列而不是数量列。
这是显示篮子的代码(Form_load)
using (var con = new SqlConnection(connectionString))
{
SqlDataAdapter dataadapter =
new SqlDataAdapter(
"select p.productname 'Product Name', b.productquantity 'Quantity', c.categoryname 'Category', p.price 'Current Price' " +
"from basket b join products p on b.productid = p.productid " +
"join Categories c on c.categoryid = p.categoryid " +
$"where b.customerid = {CustomerId}", con);
DataSet ds = new DataSet();
con.Open();
dataadapter.Fill(ds);
con.Close();
dataGridView1.DataSource = ds.Tables[0].DefaultView;
}
CustomerId 是从一个 txt 文件中收集的,该文件在他们登录时存储 CustomerId。
如果您想查看更多代码,请发表评论,我会添加。
【问题讨论】:
标签: c# sql winforms tsql datagridview