Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
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();


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..
Posted
Comments
Shambhoo kumar 24-Sep-12 0:50am    
any one help me..?

Try this:
C#
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
 
Share this answer
 
Comments
Shambhoo kumar 24-Sep-12 3:52am    
Thanks sir it's work fine..........
:)

Regard
Sham
_Amy 24-Sep-12 4:46am    
Welcome. :)
select isnull(sum(isnull(Net_Total,0)),0) FROM Factory_Pay where Factory_Name='
 
Share this answer
 
Comments
Shambhoo kumar 22-Sep-12 7:46am    
i got this msg "wrong number of arguments used with function in query expression 'isnull(sum(isnull(Net_Total,0)),0)'".
Shambhoo kumar 22-Sep-12 7:49am    
r u there...?
[no name] 22-Sep-12 8:19am    
send Me The Cmd.Text To CHeck The Error Exctaly
Shambhoo kumar 24-Sep-12 0:45am    
cmd = new OleDbCommand("select isnull(sum(isnull(Net_Total,0)),0) FROM Factory_Pay where Factory_Name='" + comboBox1.Text + "'", con);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900