|
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
/// <summary>
/// Summary description for DataProvider
/// </summary>
public class DataProvider
{
// Create the sample datasource for these exercises
// this simulates a stored procedure that returns variable value columns
public static DataTable CreateDataSource(int numValueColumns)
{
DataTable t = new DataTable();
// create the table structure
DataColumn c = new DataColumn();
c = new DataColumn();
c.DataType = System.Type.GetType("System.String");
c.ColumnName = "Category";
t.Columns.Add(c);
for (int i = 1; i <= numValueColumns; i++)
{
c = new DataColumn();
c.DataType = System.Type.GetType("System.Int32");
c.ColumnName = "Value" + i.ToString();
t.Columns.Add(c);
}
// populate the table with some sample rows of data
Random rnd = new Random();
DataRow r = t.NewRow();
r["Category"] = "North Region";
for (int i = 1; i <= numValueColumns; i++) r["Value" + i.ToString()] = rnd.Next(10, 10000);
t.Rows.Add(r);
r = t.NewRow();
r["Category"] = "South Region";
for (int i = 1; i <= numValueColumns; i++) r["Value" + i.ToString()] = rnd.Next(10, 10000);
t.Rows.Add(r);
r = t.NewRow();
r["Category"] = "East Region";
for (int i = 1; i <= numValueColumns; i++) r["Value" + i.ToString()] = rnd.Next(10, 10000);
t.Rows.Add(r);
r = t.NewRow();
r["Category"] = "West Region";
for (int i = 1; i <= numValueColumns; i++) r["Value" + i.ToString()] = rnd.Next(10, 10000);
t.Rows.Add(r);
return t;
}
}
|
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.
With a background in education, music, application development, institutional research, data governance, and business intelligence, I work for the University of Nevada, Las Vegas helping to derive useful information from institutional data. It's an old picture, but one of my favorites.