我想知道当我从sqlserver两个表中将它们加载到DataGridView和TextBoxes时如何将值转换为两位小数。这是我的代码。我尝试了txtgrandTotal.Text = Total.ToString("#, 0.00")代码,当我将数据插入数据库
时 public void loadDataToUpdate()
{
DynamicConnection con = new DynamicConnection();
try
{
con.sqlquery("SELECT p.PO_No,p.Supplier_ID,p.Date,p.RequiredDate,p.GrandTotal,b.BookName,c.ISBN_No,c.OrderQuantity,c.UnitPrice,c.Total FROM TBL_PO_Cart AS c INNER JOIN TBL_Book AS b ON c.ISBN_No = b.ISBN_No INNER JOIN TBL_PO AS p ON c.PO_No=p.PO_No where p.PO_No='" + cmbPO.Text + "'");
con.mysqlconnection();
con.datatable();
SqlDataAdapter da = new SqlDataAdapter(con.cmd);
DataSet ds = new DataSet();
da.Fill(ds);
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
txtPONo.Text = ds.Tables[0].Rows[i][0].ToString();
cmbsupID.Text = ds.Tables[0].Rows[i][1].ToString();
date1.Text = ds.Tables[0].Rows[i][2].ToString();
requireddate.Text = ds.Tables[0].Rows[i][3].ToString();
txtgrandTotal.Text = (ds.Tables[0].Rows[i][4].ToString());
}
con.dataread();
this.dataGridView1.Rows.Clear();
while (con.datareader.Read())
{
DataGridViewRow row = (DataGridViewRow)dataGridView1.Rows[0].Clone();
row.Cells[0].Value = con.datareader["BookName"].ToString();
row.Cells[1].Value = con.datareader["ISBN_No"].ToString();
row.Cells[2].Value = con.datareader["OrderQuantity"].ToString();
row.Cells[3].Value = con.datareader["UnitPrice"].ToString();
row.Cells[4].Value = con.datareader["Total"].ToString();
dataGridView1.Rows.Add(row);
}
}
所以我需要显示txtgrandTotal文本框,datagridview column3和column4,带有2位小数。请帮帮我