从存储过程执行返回的类型 [英] Returned types from stored procedure execution

查看:117
本文介绍了从存储过程执行返回的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个要执行的SP,并将groos结果保存在一边(在类字段中).
稍后,我想从该结果中获取某些行的某些列的值.

有哪些返回类型是可能的?哪一个最适合我的目标?
我知道有DataSet,DataReader,resultSet.还有什么?
它们之间的主要区别是什么?

10x可获得任何帮助

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

推荐答案

我不相信.Net中存在ResultSet类型.

您谈论访问行和列的值,因此显而易见的候选者将是您的class字段的DataTable.

来自MSDN的页面 [
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:

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;
}


这篇关于从存储过程执行返回的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆