Wednesday, May 19, 2010

Create Dynamic DataTable with DataTableManager

static DataTable dtNew;




string[] colNames = { "StudentID", "Name", "Course", "StudentClass", "MobileNo", "HomeEmail", "PT" };


string[] colTypes = { "System.String", "System.String", "System.String", "System.String", "System.String",
                                 "System.String", "System.String"};


int[] colWidth = { 10, 10, 10, 10, 10, 10, 10 };


protected void Page_Load(object sender, EventArgs e)
{
      if (!Page.IsPostBack)
          dtNew = DataTableManager.createNewTable(colNames, colTypes);
}

Friday, May 14, 2010

SQL: How to display row count / row number

select  ROW_NUMBER() OVER(ORDER BY ID,Name) AS 'Num', ID,Name

How to convert the output of a SQLDataSource.Select to a DataTable

/*Step 1 : First convert source of a SQLDataSource into a DataView */
DataView dv = (DataView)SqlDataSourceStudentsOnly.Select(DataSourceSelectArguments.Empty);
/*Step 2: Cast it to DataTable using ToTable() method of DataSet */

DataTable dt = (DataTable)dv.ToTable();