store procedure:
_________________________________________________
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[outputParms]
(
@count int output,
@sum int output
)
AS
BEGIN
declare @t table(id int identity(1,1), value int)
insert into @t
select 10 union all
select 20 union all
select 30
select @count = count(1), @sum = sum(value) from @t
select * from @t
END
.cs:
_________________________________________________
protected void Page_Load(object sender, EventArgs e)
{
SqlParameter[] parms = new SqlParameter[2];
parms[0] = new SqlParameter("@count",SqlDbType.Int);
parms[0].Direction=ParameterDirection.Output;
parms[1] = new SqlParameter("@sum", SqlDbType.Int);
parms[1].Direction = ParameterDirection.Output;
string strConn = @"server=EN0075\SQLEXPRESS; database=test; uid=reader; pwd=reader;";
DataTable dt = SqlHelper.ExecuteDataset(strConn, CommandType.StoredProcedure, "outputParms", parms).Tables[0];
Response.Write("parms[0].Value: " + parms[0].Value.ToString() + "<br>");
Response.Write("parms[1].Value: " + parms[1].Value.ToString() + "<br>");
for (int i = 0; i <dt.Rows.Count ; i++)
{
Response.Write("Rows " + Convert.ToInt16(i +1).ToString() + ":" + dt.Rows[i][1].ToString() + "<br>");
}
}
_________________________________________________
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[outputParms]
(
@count int output,
@sum int output
)
AS
BEGIN
declare @t table(id int identity(1,1), value int)
insert into @t
select 10 union all
select 20 union all
select 30
select @count = count(1), @sum = sum(value) from @t
select * from @t
END
.cs:
_________________________________________________
protected void Page_Load(object sender, EventArgs e)
{
SqlParameter[] parms = new SqlParameter[2];
parms[0] = new SqlParameter("@count",SqlDbType.Int);
parms[0].Direction=ParameterDirection.Output;
parms[1] = new SqlParameter("@sum", SqlDbType.Int);
parms[1].Direction = ParameterDirection.Output;
string strConn = @"server=EN0075\SQLEXPRESS; database=test; uid=reader; pwd=reader;";
DataTable dt = SqlHelper.ExecuteDataset(strConn, CommandType.StoredProcedure, "outputParms", parms).Tables[0];
Response.Write("parms[0].Value: " + parms[0].Value.ToString() + "<br>");
Response.Write("parms[1].Value: " + parms[1].Value.ToString() + "<br>");
for (int i = 0; i <dt.Rows.Count ; i++)
{
Response.Write("Rows " + Convert.ToInt16(i +1).ToString() + ":" + dt.Rows[i][1].ToString() + "<br>");
}
}
If opportunity doesn’t knock, build a door