Thanks for Great Support
DateBase table name: bs
Column name: total
i wanted to get SUM of total column in " textbox11 "
please help me coding for the above question. thanks in advance to all helping me at this times.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Dec 30, 2011, 10:48 AM
using System.Data.SqlClient;
SqlConnection con=new SqlConnection("connectionstring");
SqlCommand com;
String str;
private void btnsum_marks_Click(object sender, System.EventArgs e)
{
con.Open();
str = "select SUM(smarks)from student";
com = new SqlCommand(str, con);
txtsum_marks.Text =com.ExecuteScalar().ToString ();
con.Close();
}
Thanks
VulpesPosted Dec 30, 2011, 10:40 AM
string sql = "SELECT SUM(total) FROM bs";
using (SqlConnection conn = new SqlConnection(connString))
{
SqlCommand cmd = new SqlCommand(sql, conn);
conn.Open();
textBox11.Text = ((decimal)cmd.ExecuteScalar()).ToString();
}