变量aa是里面的么?
  select count(*) as aa from table1

解决方案 »

  1.   

    select aa=count(*) from table1
      

  2.   

    难道只能用select count(*) as cnt from table1
    然后用OleDbDataReader dr……来dr["cnt"]吗?
      

  3.   

    你是说
    select count(*) as aa from tabel1???
      

  4.   

    楼主,你不这样还想怎么样?你不会想直接在sql server里就赋值好给一个ASP的全局变量吧。
      

  5.   

    SqlConnection con = new SqlConnection("连接字符串");SqlCommand cmd = new SqlCommand( "Select Count(*) from table1",con );con.Open();int aa=0;
    try {
      aa = (int)cmd.ExecuteScalar();
    }
    catch{} con.Close();
      

  6.   

    set @aa int
    select @aa=count(*) from table1
      

  7.   

    aa = (int)cmd.ExecuteScalar();这个方法是可行,但只能取出一个值;
    要实现SELECT SUM(字段1) INTO :aa, SUM(字段2) INTO :bb from table1呢?
    我是想知道除了用DATAREADER读结果外,有别的快捷方法吗?
    ——就是能直接在SQL里赋值给C#的变量吗?
      

  8.   

    SqlConnection con = new SqlConnection("连接字符串");SqlCommand cmd = new SqlCommand( "Select Count(字段1) As aa,Count(字段2) asbb from table1",con );con.Open();SqlDataReader reader = cmd.ExecuteReader();int aa=0,bb=0;
    if( reader.Read() )
    {
       try {
          aa = reader.GetInt32("aa");
       }
       catch{}
       try {
          bb = reader.GetInt32("bb");
       }
       catch{}
    }reader.Close();
    con.Close();
      

  9.   

    其他的方法没有了这还不简单吗?“——就是能直接在SQL里赋值给C#的变量吗?”DataReade不就是做这个事情吗?你要在SQL Text和C#里面使用同一个变量是不可能的,二者运行的环境不一样
      

  10.   

    Declare @num
    Select @num=Count(*) from table1return @num