build temp array and return this to client | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

build temp array and return this to client

How can you loop over a data reader and save the current row to a temp array of some sort and return this array back to the caller? SqlDecimal total = 0;
SqlConnection conn = new SqlConnection("Context Connection=true");
SqlCommand cmd = new SqlCommand(@"SELECT column1, column2, column3
FROM table ", conn); conn.Open(); SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
if (rdr.GetSqlString(1) == "01")
{
// ADD the current record to a temp list
total = total + rdr.GetSqlDecimal(2);
} } SqlContext.Pipe.Send(total.ToString());
// RETURN the temp list rdr.Close();
conn.Close();
]]>