使用具有行限制的数据适配器填充数据集



我需要修改以下代码,以便限制行数。

// create the connection
OracleConnection conn = new OracleConnection("Data Source=oracledb;
    User Id=UserID;Password=Password;");
// create the command for the stored procedure
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = "SELECT_JOB_HISTORY.GetJobHistoryByEmployeeId";
cmd.CommandType = CommandType.StoredProcedure;
// add the parameters for the stored procedure including the REF CURSOR
// to retrieve the result set
cmd.Parameters.Add("p_employee_id", OracleType.Number).Value = 101;
cmd.Parameters.Add("cur_JobHistory", OracleType.Cursor).Direction =
    ParameterDirection.Output;
// createt the DataAdapter from the command and use it to fill the
// DataSet
OracleDataAdapter da = new OracleDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);//Here is where I need to limit the rows

我知道有填充方法可以进行最大计数。

public int Fill( 数据集数据集, int startRecord, int maxRecords, 字符串 srcTable)

但是,我不知道应该传递给srcTable什么。我存储的进程有一个REF_CURSOR(输出类型。REF_CURSOR)。

任何帮助都非常感谢。

srcTable 参数是对象中DataSet DataTable的名称。

编辑:

DataSet对象会在您调用表时自动添加一个表Fill如果您尚未显式创建一个表。 默认名称为"表"。 我不相信DataSet对象关心它被填充的数据类型。 它仍然创建DataTable

在你打电话给Fill()之前 你的DataAdapter. 使用名称向DataSet添加一个空表,以便能够在Fill()方法期间访问它:

ds.Tables.Add("myTableName");

然后调用适当的重载Fill()方法,如下所示:

da.Fill(ds, 1, 1000, "myTableName");
或者,

如果您只使用表的默认名称,或者不确定您创建的表的名称(可疑):

da.Fill(ds, 1, 1000, ds.Tables[0].TableName);

具体使用您的示例,它应如下所示:

OracleDataAdapter da = new OracleDataAdapter(cmd);
DataSet ds = new DataSet();
ds.Tables.Add();
da.Fill(ds, 1, maxRowCount, ds.Tables[0].TableName);//Here is where I need to limit the rows

相关内容

最新更新