我要统计xuanze这张表里type id='1'的记录数一共多少条 把得到的结果赋值给int a 
我写
  int a=Convert.ToInt16("select count([tm id]) from xuanze where xuanze.[type id]='1'");
可是调试的结果是a为null 为什么count不出来呢
在查询分析器里我select count([tm id]) from xuanze where xuanze.[type id]='1' 这样执行这句可以计算出一共多少条记录 可是为什么在c#里那样打就是null了呢

解决方案 »

  1.   

    select count([tm id]) 字段名 from xuanze where xuanze.[type id]='1' 
      

  2.   

    string sql="select count([tm id]) from xuanze where [type id]='1'";
      SqlDataAdapter comm=new SqlDataAdapter(sql,conn);
    DataSet ds=new DataSet();
    comm.Fill(ds,"xuanze");
     string aaa=sql;我这样断点调试 aaa是null 我晕了
      

  3.   

    就是啊我觉得没错误啊 为什么sql的值进不去呢
      

  4.   


    int count=ds.Tables["xuanze"].Rows.Count;
      

  5.   

    那个不是统计xuanze这张表里的行数吗 可是[我要统计的是条件为[type id]=1的行数啊
      

  6.   

    你查询的条件不就是[type id]=1的数据吗,那DataSet里的行数当然就是啦
      

  7.   

    int count=ds.Tables["xuanze"].Rows.Count;