T
Tony
Hello!
In this code snipper I use the storedprocedure RowsAndOutput that is listed
below.
What I find strange in this code is why I have to either call the
rdr.NextResult() or
rdr.Close() before I can read the output parameter called OutputParam from
the storedprocedure
I mean that after I have called while (rdr.Read()) {}
I should be able to access the output parameter from the storedprocedure but
that is not possible becuse it has not any value yet.
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(connectionString);
con.Open();
SqlCommand cmd = new SqlCommand("RowsAndOutput", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter param = cmd.Parameters.Add("@OutputParam",
SqlDbType.Int);
param.Direction = ParameterDirection.Output;
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{}
object s1 = param.Value;
while (rdr.NextResult())
{}
object s2 = param.Value;
}
ALTER procedure RowsAndOutput (@OutputParam int OUTPUT) AS
select @OutputParam = COUNT(*) from Customers
select customerID, companyName, contactName, phone from Customers
//Tony
In this code snipper I use the storedprocedure RowsAndOutput that is listed
below.
What I find strange in this code is why I have to either call the
rdr.NextResult() or
rdr.Close() before I can read the output parameter called OutputParam from
the storedprocedure
I mean that after I have called while (rdr.Read()) {}
I should be able to access the output parameter from the storedprocedure but
that is not possible becuse it has not any value yet.
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(connectionString);
con.Open();
SqlCommand cmd = new SqlCommand("RowsAndOutput", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter param = cmd.Parameters.Add("@OutputParam",
SqlDbType.Int);
param.Direction = ParameterDirection.Output;
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{}
object s1 = param.Value;
while (rdr.NextResult())
{}
object s2 = param.Value;
}
ALTER procedure RowsAndOutput (@OutputParam int OUTPUT) AS
select @OutputParam = COUNT(*) from Customers
select customerID, companyName, contactName, phone from Customers
//Tony