我用下面的命令调用有out参数的存储过程, 是可以正确执行的。 SqlParameter[] commandParameters = new SqlParameter[2];
commandParameters[0] = new SqlParameter("@serviceid", SqlDbType.Int);
commandParameters[0].Value = 0;
commandParameters[0].Direction = ParameterDirection.Output;
commandParameters[1] = new SqlParameter("@pcid", SqlDbType.Int);
commandParameters[1].Value = 0;
commandParameters[1].Direction = ParameterDirection.Output;
Database.ExecuteNonQuery(CommandType.StoredProcedure, "getfreePcidandServiceid", commandParameters);
serviceid = (int) (commandParameters[0].Value);
pcid = (int)(commandParameters[1].Value);可是这样有弊病:
一是参数数组大小必须定义好,
二是取得out参数的值要用数组顺序,不方便。如commandParameters[1].Value有没有好的获得out参数的值的方法?
commandParameters[0] = new SqlParameter("@serviceid", SqlDbType.Int);
commandParameters[0].Value = 0;
commandParameters[0].Direction = ParameterDirection.Output;
commandParameters[1] = new SqlParameter("@pcid", SqlDbType.Int);
commandParameters[1].Value = 0;
commandParameters[1].Direction = ParameterDirection.Output;
Database.ExecuteNonQuery(CommandType.StoredProcedure, "getfreePcidandServiceid", commandParameters);
serviceid = (int) (commandParameters[0].Value);
pcid = (int)(commandParameters[1].Value);可是这样有弊病:
一是参数数组大小必须定义好,
二是取得out参数的值要用数组顺序,不方便。如commandParameters[1].Value有没有好的获得out参数的值的方法?
解决方案 »
- 如何在Panel中绘制不规则形状并且使用渐变颜色填充
- C#中的常量值怎么改?
- Winform下子窗口最大化,布局的问题,请高手帮忙一起解决,谢谢!
- 急!!!!
- 初学者的一个小问题(关于TextBox.Text),请各位大侠帮忙.
- Unable to create type 'igtbar:UltraWebToolbar'.
- 学习C# 工作10年后干什么
- 关于静态类的序列化(急)
- C#版计算器
- ado.net里的dataset可以做成离线数据库,在离线状态下改变表里的内容,然后统一更新数据表..可是不知道怎么弄
- 哪位高人可以帮我解决这个问题啊:C#中如何计算并更改FOR循环打印的非静态的字符串?
- 请教一个C#图像处理问题
难道用pcid = (int)(commandParameters[@pcid].Value);
通不过的呀.
pcid = (int)(commandParameters["@pcid"].Value);
不知道你Database类里怎么写的
实际上你需要在Database类里公开SqlCommand对象.
给你一个代码参考下:
using (SqlConnection connection = new SqlConnection(SqlConnstr))
{
connection.Open();
SqlCommand command = BuildIntCommand(connection,storedProcName, parameters );
command.ExecuteNonQuery();
return (int)command.Parameters["ReturnValue"].Value;
}
你要返回多个的话,就最好公开SqlCommand对象