现在的位置: 首页 > 综合 > 正文

Ado.Net 传参注意点

2013年03月28日 ⁄ 综合 ⁄ 共 514字 ⁄ 字号 评论关闭
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。

【上篇】
【下篇】

抱歉!评论已关闭.