|
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace dpant
{
/// <summary>
/// Summary description for CustomersDataLayer
/// CustomersDataLayer is a Data Layer implementation for the Customers table of the Northwind database.
/// Public methods:
/// GetCustomers : Returns all rows from the Customers table.
/// GetCustomer : Returns only one row from the Customers table.
/// GetCustomersCount: Returns the total number of Customers rows.
///
/// Written by dpant@yahoo.com, 13/10/2007.
/// </summary>
public class CustomersDataLayer
{
public static DataTable GetCustomers()
{
// Return all rows from the Customers table.
return DataLayerHelper.Get("SELECT [CustomerID], [CompanyName], [Country] FROM [Customers]");
}
public static DataTable GetCustomer(int CustomerID)
{
// Return only one row from the Customers table.
return DataLayerHelper.GetById("SELECT [CustomerID], [CompanyName], [Country] FROM [Customers] WHERE [CustomerID] = @CustomerID", "CustomerID", CustomerID.ToString());
}
public static int GetCustomersCount()
{
return (int)DataLayerHelper.ExecuteScalar("SELECT COUNT(CustomerID) FROM Customers");
}
public static DataTable GetPageCustomers(int startIndex, int maxPageRows)
{
// Delete the unneccessary rows and return the datatable.
DataTable tbl= GetCustomers();
int maxRows = GetCustomersCount();
int max = startIndex + (maxPageRows - 1);
if (max > maxRows)
max = maxRows;
for (int i = 0; i < startIndex; i++)
tbl.Rows[i].Delete();
for (int i = max + 1; i < maxRows; i++)
tbl.Rows[i].Delete();
return tbl;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.