日期:2014-05-18  浏览次数:20458 次

select top 1 id from title order by id desc
C#中如何将上面select top 1 id from title order by id desc这句的ID值传给一个变量,如TID

------解决方案--------------------
select top 1 id as TId from title order by id desc
------解决方案--------------------
变量是存储过程中的如:

declare @tid int 
select top 1 @tid =id from title order by id desc 


变量是C#程序中的:


sqlconnection conn=new sqlconnection(连接字符串);
sqlcommand cmd=new sqlcommand("select top 1 id from title order by id desc",conn);
int tid=convert.ToInt32(cmd.ExecuteScalar());