Karan Gupta

Karan Gupta

  • NA
  • 29
  • 15k

how to print sum(amount) in label

Apr 10 2015 9:10 AM
i want to print a sum (amount) in label windows form --- from sql 
 
my code is ... it is not working 
 
 i
SqlCommand com = new SqlCommand("SELECT sum(amount) from custpurches where name='" + comboBox1.Text + "'", con);
try
{
con.Open();
SqlDataReader dr = com.ExecuteReader();
con.Close();
if (dr.Read())
{
label1.Text = dr["amount"].ToString();
dr.Close();
con.Close();
}
else
{
MessageBox.Show("error");
dr.Close();
con.Close();
}
}
catch (Exception ex)
{
MessageBox.Show("Try again or Refresh", "message");
}