SQL 存储过程中的 output 怎么用?并且在程序中我需要返回这个output的值怎么返回。
求各位高手指点。急需解答!
求各位高手指点。急需解答!
解决方案 »
- 菜鸟 做 项目
- girdview数据显示
- 亲,求救啊~~~HTML元素控件一直找不到
- 进来看看..MYSQL的
- Visual Studio 2008 + MVC 开发,前台中文字的问题
- CheckBoxList_SelectedIndexChanged的问题,解决了另送100分,急啊,在线等,帮顶有分
- 求一个函数或代码:弹出让用户确认的窗口,并根据用户的选择返回不同的值。
- 如何保存文本格式
- 怪事了! 为何我在winxp下安装了.net framework等组件,可就是无法运行.net程序!!!
- 求助:同一帐号多点登陆问题
- 如何用js+asp.net mvc2做个OA 日程管理的日历,急~~
- 关于form表单提交input file上传图片问题
int newID = command.parameters["@RoleID"].value;
http://bbs.5d.cn/Detail.aspx?forum=10&id=1357160&page=1
楼上的方法可以的cmd.Parameters["@PageCount"].Direction = ParameterDirection.Output;如果需要多个返回参数,需要在方法上添加参数out int PageCount, out int ListCount
我的示例
public static DataSet ExecuteDataSetByStoredProcedure(string SPName, out int PageCount, out int ListCount, params SqlParameter[] cmdParms)
{
using (SqlConnection conn = new SqlConnection(ConnStr))
{
if (conn.State == ConnectionState.Closed) { conn.Open(); }//判断连接是否打开
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = SPName;
cmd.CommandType = CommandType.StoredProcedure;
PrepareCommand(cmd, cmdParms);
cmd.Parameters.Add("@PageCount", SqlDbType.Int);
cmd.Parameters["@PageCount"].Direction = ParameterDirection.Output;
cmd.Parameters.Add("@ListCount", SqlDbType.Int);
cmd.Parameters["@ListCount"].Direction = ParameterDirection.Output;
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
PageCount = (int)cmd.Parameters["@PageCount"].Value;
ListCount = (int)cmd.Parameters["@ListCount"].Value;
return ds;
}
}
}
然后调用的时候加上相应参数,并在参数前加 out
截至 2011-10-21 10:10:15 前:
你已发帖 4 个, 未结贴 1 个;
结贴率为: 75.00%
当您的问题得到解答后请及时结贴.
http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html
http://topic.csdn.net/u/20100428/09/BC9E0908-F250-42A6-8765-B50A82FE186A.html
http://topic.csdn.net/u/20100626/09/f35a4763-4b59-49c3-8061-d48fdbc29561.html如何给分和结贴?
http://community.csdn.net/Help/HelpCenter.htm#结帖如何给自己的回帖中也加上签名?
http://blog.csdn.net/q107770540/archive/2011/03/15/6250007.aspx
ALTER PROCEDURE [dbo].[UP_Red_Red_Mac_select]
@mac nvarchar(50), --传的参数
@gametype int ,
@ip nvarchar(50), --获取本机的IP
@code varchar(50) output
AS
declare @codetemp varchar(50)
declare @idtemp int
if(select count(1) from Red_Mac where mac=@mac and GameType=@gametype)=0
begin
select @idtemp=id, @codetemp=code from red_code where IsAction=1
if (@codetemp!='')
begin
INSERT INTO [Red_Mac]
([mac]
,[ip]
,[cretime]
,[code]
,[GameType])
VALUES
(@mac,@ip,getdate(),@codetemp,@gametype)
update red_code set IsAction=0,updatetime=getdate() where id=@idtemp
select @code=code from Red_Mac where mac=@mac and GameType=@gametype
return 1 --发送成功
end
else
begin
return -1 --激活码发完
end
end
else
begin
select @code=code from Red_Mac where mac=@mac and GameType=@gametype
return -2 --已经申请过激活码
end
程序的调用:
public string Get_Code(string mac, int gametype)
{
int rowsAffected = 0;
string code=string.Empty;
StringBuilder strSql = new StringBuilder();
SqlParameter[] parameters = {
new SqlParameter("@mac", SqlDbType.NVarChar,50),
new SqlParameter("@gametype", SqlDbType.Int,4),
new SqlParameter("@ip", SqlDbType.NVarChar,50),
new SqlParameter("@code",SqlDbType.NVarChar,50)
};
parameters[0].Value = mac;
parameters[1].Value = gametype;
parameters[2].Value = WebConfig.GetIp;
parameters[3].Direction = ParameterDirection.Output;
int obj = DbHelperSQL.RunProcedure("UP_Red_Red_Mac_select", parameters, out rowsAffected);
if (obj == 1 ||obj==-2)
{
return obj+"|"+parameters[3].Value.ToString();
}
else
{
return "-1";
}
}