DataTable GetPagedTable(DataTable dt, currentPageIndex, pageSize)
{
(currentPageIndex == )
dt;
DataTable newdt = dt.Copy();
newdt.Clear();
rowbegin = (currentPageIndex - ) * pageSize;
rowend = currentPageIndex * pageSize;
(rowbegin >= dt.Rows.Count)
newdt;
(rowend > dt.Rows.Count)
rowend = dt.Rows.Count;
( i = rowbegin; i <= rowend - ; i++)
{
DataRow newdr = newdt.NewRow();
DataRow dr = dt.Rows[i];
(DataColumn column dt.Columns)
{
newdr[column.ColumnName] = dr[column.ColumnName];
}
newdt.Rows.Add(newdr);
}
newdt;
}
DataTable CompareTables(DataTable first, DataTable second)
{
first.TableName = ;
second.TableName = ;
DataTable table = DataTable();
{
(DataSet ds = DataSet())
{
ds.Tables.AddRange( DataTable[] { first.Copy(), second.Copy() });
DataColumn[] firstcolumns = DataColumn[ds.Tables[].Columns.Count];
( i = ; i < firstcolumns.Length; i++)
{
firstcolumns[i] = ds.Tables[].Columns[i];
}
DataColumn[] secondcolumns = DataColumn[ds.Tables[].Columns.Count];
( i = ; i < secondcolumns.Length; i++)
{
secondcolumns[i] = ds.Tables[].Columns[i];
}
DataRelation r = DataRelation(.Empty, firstcolumns, secondcolumns, );
ds.Relations.Add(r);
( i = ; i < first.Columns.Count; i++)
{
table.Columns.Add(first.Columns[i].ColumnName, first.Columns[i].DataType);
}
table.BeginLoadData();
(DataRow parentrow ds.Tables[].Rows)
{
DataRow[] childrows = parentrow.GetChildRows(r);
(childrows == || childrows.Length == )
table.LoadDataRow(parentrow.ItemArray, );
}
table.EndLoadData();
}
}
(Exception ex)
{
ex;
}
table;
}
USE pubsGO -- USE the SELECT statement with a simple CASE function SELECT Category = CASE type WHEN 'popular _ comp 'then' popular Computing 'when' mod _ cooke' THEN 'modern cooking' when' business 'then' Business 'when' psychology 'then' Psychology 'when' trad _ cooke' then' Traditional Cooking 'else' Not yet categorized' END, CAST (title AS varchar (25) AS 'shortened title', price AS PriceFROM titlesWHERE price is not nullorder by typ E, priceCOMPUTE AVG (price) BY typeGO -- SELECT 'price Category '= case when Price is null then' Not yet priced 'when price <10 THEN 'Very Reasonable using the SELECT statement with simple CASE function and CASE search function title 'when price> = 10 and price <20 then' Coffee Table Title 'else' Expensive book! 'End, CAST (title AS varchar (20) AS 'shortened title' FROM titlesORDER BY priceGO -- use the CASE function with SUBSTRING and select substring (RTRIM (. au_fname) + ''+ RTRIM (. au_lname) + ''), 1, 25) AS Name,. au_id, ta. title_id, Type = case when substring (ta. title_id, 1, 2) = 'bus' THEN 'business' when substring (ta. title_id, 1, 2) = 'mc 'then' Modern cooking' when substring (ta. title_id, 1, 2) = 'pc' then' Popular Computing 'when SUBSTRING (ta. title_id, 1, 2) = 'ps' THEN 'psychology 'when SUBSTRING (ta. title_id, 1, 2) = 'tc 'then' Traditional cooking' ENDFROM titleauthor ta JOIN authors a ON ta. au_id =. au_id --