Ado.Net 传参注意点

create proc p_test
@total int =1 output
as
begin
    if(@total=1)
    begin
        return
    end
    select * from test where uid=@total
end

 

SqlDataAdapter sda = new SqlDataAdapter("p_test", conn);
                sda.SelectCommand.CommandType = CommandType.StoredProcedure;
                SqlParameter pTotal = new SqlParameter("@total", SqlDbType.Int, 4);
                pTotal.Direction = ParameterDirection.InputOutput;
                sda.SelectCommand.Parameters.Add(pTotal);

使用Profiler监控发现传进去的 @total是null,但是实际测试发现如果没有对pTotal赋值,传进去的其实是存储过程定义的默认值而不是null。

posted @ 2011-06-17 17:19  再快一点  阅读(226)  评论(0编辑  收藏  举报