Asp中如何获取满足某个条件的记录总数?
stringsql="selectcount(*)ascountsfromzhoujiwhereuserid='ccc'";//rs.opensql;SqlConnect...
string sql = "select count(*) as counts from zhouji where userid='ccc'";
//rs.open sql;
SqlConnection Conn = new SqlConnection();
Conn.ConnectionString = "Data Source=.;Initial Catalog=DB_TFM_DATA.MDF;user id=sa;password=sa";
Conn.Open();
SqlCommand sc = new SqlCommand(sql, Conn);
sc.CommandType = CommandType.Text;
sc.ExecuteNonQuery();
Conn.Close();
Response.Write("<script>alert('rs.counts');</script>");
我要得到zhouji表中满足userid='ccc'的记录数。请尽量详细地解释下,最好能让我直接复制。。。这些代码有错的希望大家指正。谢谢 展开
//rs.open sql;
SqlConnection Conn = new SqlConnection();
Conn.ConnectionString = "Data Source=.;Initial Catalog=DB_TFM_DATA.MDF;user id=sa;password=sa";
Conn.Open();
SqlCommand sc = new SqlCommand(sql, Conn);
sc.CommandType = CommandType.Text;
sc.ExecuteNonQuery();
Conn.Close();
Response.Write("<script>alert('rs.counts');</script>");
我要得到zhouji表中满足userid='ccc'的记录数。请尽量详细地解释下,最好能让我直接复制。。。这些代码有错的希望大家指正。谢谢 展开
1个回答
展开全部
string sql = "select count(*) as counts from zhouji where userid='ccc'";
//rs.open sql;
SqlConnection Conn = new SqlConnection();
Conn.ConnectionString = "Data Source=.;Initial Catalog=DB_TFM_DATA.MDF;user id=sa;password=sa";
Conn.Open();
SqlCommand sc = new SqlCommand(sql, Conn);
sc.CommandType = CommandType.Text;
//sc.ExecuteNonQuery(); 这个用来执行更新添加的语句
int scount =int.Parse(cmd.ExecuteScalar().ToString()); //ExecuteScalar这个才是获取SQL查询的第一行第一列的值
Response.Write("<script>alert('" + scount + "');</script>");
Conn.Close();
//Response.Write("<script>alert('rs.counts');</script>");
//rs.open sql;
SqlConnection Conn = new SqlConnection();
Conn.ConnectionString = "Data Source=.;Initial Catalog=DB_TFM_DATA.MDF;user id=sa;password=sa";
Conn.Open();
SqlCommand sc = new SqlCommand(sql, Conn);
sc.CommandType = CommandType.Text;
//sc.ExecuteNonQuery(); 这个用来执行更新添加的语句
int scount =int.Parse(cmd.ExecuteScalar().ToString()); //ExecuteScalar这个才是获取SQL查询的第一行第一列的值
Response.Write("<script>alert('" + scount + "');</script>");
Conn.Close();
//Response.Write("<script>alert('rs.counts');</script>");
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询