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.
I wanted to get SUM of total column in " textbox11 ", from DateBase table name: bs Column name: total
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

VulpesRank #55 · 29.2K reputationPosted Dec 30, 2011, 5:40 AM EST
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();
}
Satyapriya NayakRank #47 · 31.5K reputationPosted Dec 30, 2011, 5:48 AM EST
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