C# 4.0 将标签格式设置为、、,,。从SQL查询
这是我的密码C# 4.0 将标签格式设置为、、,,。从SQL查询,c#-4.0,C# 4.0,这是我的密码 SqlConnection sqlConn = new SqlConnection(MyClass.GlobalConn()); sqlConn.Open(); try { string cmdStr = "Select CONVERT (char(12), CONVERT(money,sum(ProductAmt))),CONVERT (char(12), CONVERT(money,sum(ServiceAmt))) from MyTable"; SqlCo
SqlConnection sqlConn = new SqlConnection(MyClass.GlobalConn());
sqlConn.Open();
try
{
string cmdStr = "Select CONVERT (char(12), CONVERT(money,sum(ProductAmt))),CONVERT (char(12), CONVERT(money,sum(ServiceAmt))) from MyTable";
SqlCommand cmd = new SqlCommand(cmdStr, sqlConn);
SqlDataReader dR;
dR = cmd.ExecuteReader();
while (dR.Read())
{
label1.Text = (dR[0].ToString());
label1.Text = (dR[1].ToString());
}
}
我的Label1和label2输出格式为。
我希望它在,,。格式,我怎样才能用那种格式制作呢
尝试label1时出错。Text=dR[0]。ToString 2
提前感谢。这里有一个可行的方法:
public static string GetCurrencyString(string currString)
{
decimal moneyvalue;
if (Decimal.TryParse(currString, out moneyvalue))
{
return String.Format("{0:C}", moneyvalue);
}
else
{
return null;
}
}
可以这样称呼:
label1.Text = GetCurrencyString(dR[0].ToString())
会出现什么样的错误?请编辑也请尝试使用Console.out.WriteLine来回送变量的内容。