Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-server-2005 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 22-Sep-12 2:38am
Comments
shambhoo kumar at 24-Sep-12 0:50am
   
any one help me..?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
Comments
shambhoo kumar at 24-Sep-12 3:52am
   
Thanks sir it's work fine..........
:)
 
Regard
Sham
_Amy at 24-Sep-12 4:46am
   
Welcome. :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

select isnull(sum(isnull(Net_Total,0)),0) FROM Factory_Pay where Factory_Name='
  Permalink  
Comments
shambhoo kumar at 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 at 22-Sep-12 7:49am
   
r u there...?
md_refay at 22-Sep-12 8:19am
   
send Me The Cmd.Text To CHeck The Error Exctaly
shambhoo kumar at 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)



Advertise | Privacy | Mobile
Web03 | 2.8.150302.1 | Last Updated 24 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100