问题描述
我想从sql数据库中获取注册成员总数以显示在aspx页上.
请帮助实现这一目标.
福尔是我尝试过的代码
SqlConnection cn =新的SqlConnection();
cn.ConnectionString = ConfigurationManager.ConnectionStrings ["abcConnectionString"].ConnectionString;
字符串sql =从reg中选择count(email)";
SqlCommand cmd =新的SqlCommand(sql,cn);
试试
{
cn.Open();
int memberCount = cmd.ExecuteNonQuery();
lbl_memberCount.Text = memberCount.ToString();
会话["memberCount"] = memberCount;
}
catch(ex ex例外)
{
Response.Write(ex.Message);
}
I want to get total no of registered members from sql database to show on aspx page.
plz help to achieve this..
Foll is the code i tried
SqlConnection cn = new SqlConnection();
cn.ConnectionString = ConfigurationManager.ConnectionStrings["abcConnectionString"].ConnectionString;
String sql = "select count(email) from reg";
SqlCommand cmd = new SqlCommand(sql, cn);
try
{
cn.Open();
int memberCount = cmd.ExecuteNonQuery();
lbl_memberCount.Text = memberCount.ToString();
Session["memberCount"] = memberCount;
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
推荐答案
try
{
cn.Open();
int memberCount = int32.parse(cmd.ExecuteScalar());
lbl_memberCount.Text = memberCount.ToString();
Session["memberCount"] = memberCount;
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
这篇关于从数据库中获取计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!