在SQL查询中计算空值 [英] calculate null value in sql query
本文介绍了在SQL查询中计算空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
cmd = new OleDbCommand("select sum(Net_Total) FROM Factory_Pay where Factory_Name='" + comboBox1.Text + "'", con);
dr = cmd.ExecuteReader();
while (dr.Read())
{
if (dr.HasRows)
{
double dd = Convert.ToDouble(dr[0].ToString());
label1.Text = "Grand Total : " + dd.ToString("0,0.00", CultureInfo.CreateSpecificCulture("Hi-In"));
}
else
{
MessageBox.Show("No Record found", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
dr.Close();
我正在使用此代码来计算总金额,但是我收到了一些错误消息,因为表中的工厂名称列可用,但Net_Total列包含空值....
错误消息为:输入字符串的格式不正确";
所以任何人都可以帮助我..
i m using this code to calculate total amount but i got some error msg because factory name column available in table but Net_Total column contain null value....
error msg is : "Input string was not in correct formate ";
so any one help me..
推荐答案
尝试一下:
Try this:
cmd = new OleDbCommand("select sum(Net_Total) FROM Factory_Pay where Factory_Name='" + comboBox1.Text + "'", con);
dr = cmd.ExecuteReader();
while (dr.Read())
{
if (dr.HasRows)
{
//Here from database some values are coming null. You need to check for null values also
if(dr[0] != DBNull.Value){
double dd = Convert.ToDouble(dr[0].ToString());
label1.Text = "Grand Total : " + dd.ToString("0,0.00", CultureInfo.CreateSpecificCulture("Hi-In"));
}
}
else
{
MessageBox.Show("No Record found", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
dr.Close();
--Amit
--Amit
从Factory_Pay中选择isull(sum(isnull(Net_Total,0)),0),其中Factory_Name =''
select isnull(sum(isnull(Net_Total,0)),0) FROM Factory_Pay where Factory_Name=''
这篇关于在SQL查询中计算空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文