Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a SP I want to execute and save the groos result aside (in a class field).
Later on I want to acquire the values of some columns for some rows from this result.

What returned types are possible? Which one is the most sutiable for my goal?
I know there are DataSet, DataReader, resultSet. what else?
What is the main difference between them ?

10x for any assistance
Posted

1 solution

I do not believe that there is a ResultSet type in .Net.

You talk about accessing the values of rows and columns so the obvious candidate would be a DataTable for your class field.

This page from MSDN[^] shows how to execute the SP using a DataReader.

You can convert that to a DataTable using something like this:

C#
public static DataTable ReaderToTable(SqlDataReader reader)
{
    DataTable newTable = new DataTable();
    DataColumn col;
    DataRow row;
    int i;

    for (i = 0; i < reader.FieldCount; i++)
    {
        col = new DataColumn();
        col.ColumnName = reader.GetName(i);
        col.DataType = reader.GetFieldType(i);

        newTable.Columns.Add(col);
    }

    while (reader.Read())
    {
        row = newTable.NewRow();
        for (i = 0; i < reader.FieldCount; i++)
        {
            row[i] = reader[i];
        }

        newTable.Rows.Add(row);
    }

    return newTable;
}
 
Share this answer
 
Comments
elad2109 15-Mar-11 5:35am    
thanks. i have a stored procedure that returns 3 tables.
Do you know how can I read these 3 tables using dataReader?
elad2109 15-Mar-11 5:41am    
found the answer:
dataReader.NextResult() brings you the next dataTable
Henry Minute 15-Mar-11 8:06am    
Good.

I knew there was a method but was struggling to remember it's name.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900