我在ASP.NET中,要从数据库的表score中查询出男性的所有个数,然后把它Response.Write();出来,要怎么做呀?在线等,急!!!!

解决方案 »

  1.   

    ....
    Select Count(id) From [Table] Where gender = '1'
    如果 男性标示是1 的话 
    获取这个值最简单的办法就是 
      

  2.   

    string sqltxt = "select count(*) from em.T_COMM_CUSTOMER ”; 
    OleDbConnection con = new OleDbConnection(ConnectionDB2String); 
    con.Open(); 
    OleDbCommand cmd = new OleDbCommand(sqltxt, con); 
    int a=cmd.ExecuteScalar(); 
    con.Close();
    Textbox1.Text=a.Tostring();
      

  3.   


    using(sqlconnection conn = new sqlconnection("连接字符串"))
    {
       sqlcommand cmd = conn.createcommand();
       cmd.commandtype=commandtype.text;
       cmd.commandtext="SELECT count(name) FROM score where 性别=男性";
       if(conn.state != connection.open)
         conn.open();
       int i = cmd.executenonquery();
       i 就是个数,
    }没有用开发环境代码可能有错的地方
      

  4.   

    SELECT count(name) FROM score where 性别=男性
      

  5.   

    string sqltxt = "select count(*) from score where 性别=‘男’”; 
    OleDbConnection con = new OleDbConnection(ConnectionDB2String); 
    con.Open(); 
    OleDbCommand cmd = new OleDbCommand(sqltxt, con); 
    int a=Convert.ToInt32(cmd.ExecuteScalar()); 
    con.Close();
    Textbox1.Text=a.Tostring();
      

  6.   


    //如果你是Access数据库.就用
             int manCounts = 0; //男生总数
            string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=abcd;Data Source=md1.mdb";
            using (OleDbConnection conn = new OleDbConnection(strConn))
            {
                conn.Open();
                OleDbCommand cmd = new OleDbCommand("select count(*) from score where sex = '男'"); //where sex ='男' 改成合适你的.
                manCounts = int.Parse(cmd.ExecuteScalar().ToString());
            }
      

  7.   


    //如果是sql数据库
             int manCounts = 0;
            //数据库边接字符串
            string strConn = "Data Source=.;Initial Catalog=Wzf;Persist Security Info=True;User ID=sa;Password=abc";    
            using (SqlConnection conn = new SqlConnection(strConn))
            {
                onn.Open();
                SqlCommand cmd = new OleDbCommand("select count(*) from score where sex = '男'");//where sex ='男' 改成合适你的.
                manCounts = int.Parse(cmd.ExecuteScalar().ToString());
            }
      

  8.   

    如果不考虑异常处理string sql = "SELECT count(*) FROM score where sex = 'M'";
    SqlConnection cn = new SqlConnection("server=.;uid=sa;pwd=;database=yourdatabase"); 
    SqlCommand cmd = new SqlCommand(sql, cn); 
    cn.Open();
    int a = (int)cmd.ExecuteScalar(); 
    cn.Close();
    Response.Write(a);
      

  9.   

    Select Count(id) From 表 Where gender = '男' 最后用数字代替,如1表示男con,open();
    .......
    用ExecScalar返回该SQL语句执行的首行首列就行了,很简单
      

  10.   

    SQL 语句做很简单:select count(*) from [Table] where Sex = 1 说明: 如果SEX是表示性别的一列的列名,而且规定1为男性,0为女性。此字段设置为int类型。
      

  11.   

    string sql = "SELECT count(*) FROM score where Gender = '男'";
    using(SqlConnection conn = new SqlConnection(<<connectionstring>>)){
    SqlCommand cmd = conn.CreateCommand();
    cmd.CommandText = sql;
    conn.Open();
    int count = (int)cmd.ExecuteScalar();
    Response.Write(count);
    }
      

  12.   

    用ExecuteScalar执行SELECT count(name) FROM score,将返回一个整形,或用SELECT count(name) as cn FROM score,用datareader读cn字段,也可以得到值
      

  13.   

    写成储存过程: CREATE PROC mencount
    (
      @mycount int output
    )
    AS
    BEGIN
    SELECT @mycount=count(*) FROM score where Gender ='1';
    END
      

  14.   

    string sql = "SELECT count(*) FROM score where sex = 'M'"; 
    SqlConnection cn = new SqlConnection("server=.;uid=sa;pwd=;database=yourdatabase"); 
    SqlCommand cmd = new SqlCommand(sql, cn); 
    cn.Open(); 
    int a = (int)cmd.ExecuteScalar(); 
    cn.Close(); 
    Response.Write(a);
      

  15.   

    string sql = "SELECT count(1) FROM score where sex = 'M'"; 
    SqlConnection cn = new SqlConnection("server=.;uid=sa;pwd=;database=yourdatabase"); 
    SqlCommand cmd = new SqlCommand(sql, cn); 
    cn.Open(); 
    int a = (int)cmd.ExecuteScalar(); 
      

  16.   

    select count(*) from score where sex='男'
    取值 DataRow[0].toString();
      

  17.   

    这样的题实在是简单的,怎么会有这么多人回答?而我的问题呢???。
    http://topic.csdn.net/u/20080707/09/0702a610-1bd2-46e6-89ca-d352c3f192ce.html
      

  18.   

    string sql = "SELECT count(*) FROM score where sex= '男'"; 
    using(SqlConnection conn = new SqlConnection(连接串)){ 
    SqlCommand cmd = conn.CreateCommand(); 
    cmd.CommandText = sql; 
    if(conn.State = ConnectionState.Closed)
    {
    conn.Open(); 
    }
    int count = (int)cmd.ExecuteScalar(); 
    Response.Write(count); 
    }
      

  19.   

    string sql = "SELECT count(*) FROM score where sex= '男'"; 
    using(SqlConnection conn = new SqlConnection(连接串)){ 
    SqlCommand cmd = conn.CreateCommand(); 
    cmd.CommandText = sql; 
    if(conn.State = ConnectionState.Closed) 

    conn.Open(); 

    int count = (int)cmd.ExecuteScalar(); 
    Response.Write(count); 
    }