示例代码:
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM MyTable", connection);
DataSet dataSet = new DataSet();
adapter.Fill(dataSet);
return dataSet;
}
示例代码:
using (SqlConnection connection = new SqlConnection(connectionString))
{
string query = "SELECT * FROM MyTable";
await connection.OpenAsync();
SqlCommand command = new SqlCommand(query, connection);
SqlDataReader reader = await command.ExecuteReaderAsync(CommandBehavior.CloseConnection);
return reader;
}
示例代码:
string query = "SELECT * FROM MyTable ORDER BY ID OFFSET {0} ROWS FETCH NEXT {1} ROWS ONLY";
int startRowIndex = 0; // the initial record to start
int pageSize = 10; // the number of records to retrieve
string sql = string.Format(query, startRowIndex, pageSize);
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(sql, connection);
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataSet dataSet = new DataSet();
adapter.Fill(dataSet);
return dataSet;
}