表名:样本
ID| Name | Amount
--|-------|-----
1 | sam | 12
----------|-----
2 | samp1 | 25
标记
<asp:Label runat="server" ID="lblsupcount"></asp:Label>
如何在c#中编写代码
答案 0 :(得分:1)
SqlConnection conn=new SqlConnection("your DB connection string"); //connect to the database here
conn.Open();
SqlDataAdapter sda=new SqlDataAdapter("SELECT SUM(Amount) FROM sample",conn);
conn.Close();
DataTable dt= new DataTable();
sda.Fill(dt);
lblsupcount.Text=dt.Rows[0][0].toString();