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
@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);
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。