我以前写后台
一般都用 public static List<Model> SelectByother(string other)
{
   sql=select  top 4 * from tab where 1=1
   sql+=other;
   SqlDataReader read=DBHelper.Search(sql,CommandType.Text);
            while(read.Read())
            {
                MessageModel m=new MessageModel();
                m.MessageId = int.Parse(read[0].ToString());
                。省略                l.Add(m);
            }
            read.Close();
            return l;
}我所有的方法都没用存储过程
 我现在就想把这个方法写在存储过程里 直接掉存储过程
但是不知道怎么传参自己试着写了一个 按自己的思路写得 
create proc Selectvideobyother(@other varchar(100),@count int)
as begin
     select top @count * from video_tab where 1=1 @other
end
GO
我知道不对 就请高手指教下,怎么修改 
根据2个条件 1是显示几条数据 2是根据自定义条件!

解决方案 »

  1.   

    SqlParameter para;然后调用SqlDataReader时,可以带上para参数就行了CommandType要设置为存储过程
      

  2.   

    我知道 我要的存储过程方法
    我想以后不在这写sql语句
    而是写成存储过程 然后给存储过程传2值
    实现功能
      

  3.   


    /*declare @other varchar(100),@count int
    set @other=''
    set @count=10
    exec Selectvideobyother @other,@count
    */
    create proc Selectvideobyother(@other varchar(100),@count int) 
    as
    exec('select top '+@count+' * from video_tab where 1=1 '+@other+'')
      

  4.   

    @sqlStr = 'select top @count * from video_tab where 1=1 ' + @other 
    exec @sqlStr