日期:2014-05-17  浏览次数:20339 次

.net调用有返回值的存储过程怎么接收参数
C# code

SqlParameter[] sqladdOrder = { 
                                             new SqlParameter("@o_tid", "129"), 
                                             new SqlParameter("@o_name", "1"), 
                                             new SqlParameter("@o_num", "1"), 
                                             new SqlParameter("@o_sex", "2"), 
                                             new SqlParameter("@o_tel", "1"), 
                                             new SqlParameter("@o_address", "1"), 
                                             new SqlParameter("@o_hukou", "1"), 
                                             new SqlParameter("@o_email", "1"), 
                                             new SqlParameter("@o_remark", "1"), 
                                             new SqlParameter("@o_from", "0"), 
                                             new SqlParameter("@o_uid", "1"),
                                             new SqlParameter("@o_ordernumber","0"),
                                             new SqlParameter("@dingdanhao",SqlDbType.Int) };
        sqladdOrder[12].Direction = ParameterDirection.Output;
        int i = SqlHelper.ExecuteCommand("zy_TuangouOrderAdd", CommandType.StoredProcedure, sqladdOrder);
        string a = sqladdOrder[12].Value.ToString();
        Response.Write(a);


这是我写的 但是不行啊未将对象引用到实例 sqladdOrder[12].Value.ToString()里面没有值是null

------解决方案--------------------
你sp的返回参数是output还是return呢??另外按你写的,若是output,假如返回的是null,你tostring()自然就错了哈,若sp里没判断,程序里加上判断是否为null吧
------解决方案--------------------
以下是一个分页查询,并返回数据总行数的存储过程的调用
//查看详情
public DataSet GetDetailExamInformation(int pageSize, int currentPage, string where, out int count)
{
OleDbParameter[] parameters = {
new OleDbParameter("@pageSize",OleDbType.Integer),
new OleDbParameter("@currentPage",OleDbType.Integer),
new OleDbParameter("@Where", OleDbType.VarChar,2000), 
new OleDbParameter("@totalCount", OleDbType.Integer)
};
parameters[3].Direction = ParameterDirection.Output;
parameters[0].Value = pageSize;
parameters[1].Value = currentPage;
parameters[2].Value = where == null ? "" : where;
DataSet ds = OleDBHelper.RunProcedure("proc_Get_DetailExamInfomation", parameters, "tablename");
count = int.Parse(parameters[3].Value.ToString());
return ds;
}
------解决方案--------------------
第一:确认你的@dingdanhao字段有值
第二:int i = SqlHelper.ExecuteCommand("zy_TuangouOrderAdd",CommandType.StoredProcedure, sqladdOrder);

zy_TuangouOrderAdd是存储过程名字吗,这个SqlHelper.ExecuteCommand方法写对了吗

i有没有值?

第三:
string a = sqladdOrder[12].Value.ToString();
你接收的是整型的值,怎么可以放tostring?
改成:
int a = Convert.ToInt32(sqladdOrder[12].Value);