在 C# 中,可以使用 OracleDataAdapter 和 DataSet 类来从 Oracle 数据库中检索数据并指定每页记录数。

以下是一个示例代码,显示如何检索从 Oracle 数据库中的 Employee 表中的数据,并指定每页记录数为 10:

using System;
using System.Data;
using System.Data.OracleClient;

public class Program
{
    static void Main(string[] args)
    {
        string connectionString = "Data Source=myOracleDB;User ID=myUsername;Password=myPassword;";
        string query = "SELECT * FROM Employee";
        int pageSize = 10;
        int page = 1;
        int startIndex = (page - 1) * pageSize + 1;
        int endIndex = startIndex + pageSize - 1;

        using (OracleConnection connection = new OracleConnection(connectionString))
        {
            using (OracleDataAdapter adapter = new OracleDataAdapter(query, connection))
            {
                DataSet dataSet = new DataSet();

                adapter.Fill(startIndex, endIndex, dataSet, "Employee");

                foreach (DataRow row in dataSet.Tables["Employee"].Rows)
                {
                    Console.WriteLine(row["EmployeeID"].ToString() + " " + row["LastName"].ToString() + " " + row["FirstName"].ToString());
                }
            }
        }
    }
}

在以上代码中,我们首先定义了一个连接字符串和一个查询字符串。然后,我们指定每页记录数为 10,并确定要检索的页数和开始和结束索引。接下来,我们使用 OracleDataAdapter 和 DataSet 类从 Oracle 数据库中检索数据,并使用 Fill 方法指定要检索的记录数和表名。最后,我们遍历 DataTable 并输出每个 Employee 的 ID、LastName 和 FirstName。

注意,这个示例中使用的 OracleConnection 和 OracleDataAdapter 类是已经过时的,应该使用 Oracle.ManagedDataAccess.Client 命名空间中的类。

C# Oracle 分页查询 - 每页记录数指定

原文地址: https://www.cveoy.top/t/topic/n6Ij 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录