例如:select COUNT(*) AS 总记录数
           from Drug_Info,Stock
           where Stock.drug_ID=Drug_Info.drug_ID and Stock.stock_qty<Drug_Info.lower_limit
      我用SQL语句count得出总记录数,怎么赋值给一个变量后调用这个变量?最好有相应的代码参考。sqlc#count赋值

解决方案 »

  1.   

    declare @icount int
    select @icount = COUNT(*) 
               from Drug_Info,Stock
               where Stock.drug_ID=Drug_Info.drug_ID and Stock.stock_qty<Drug_Info.lower_limitif @icount ......
      

  2.   

    sqlCommand.ExecuteScalar()执行查询,并返回查询所返回的结果集中第一行的第一列。 忽略其他列或行。
      

  3.   


    SqlConnection conn = new SqlConnection (链接数据库字符串);
    SqlCommond cmd = new SqlCommond(SQL语句, conn);//将取到的值赋值给变量
    int a  =convert.Toint32( cmd .ExecuteScalar());