Error
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.

datatable

Sets the maximum length of a text column in datatable.
Wednesday, 01 February 2012 01:20
Sets the maximum length of a text column in datatable.


DataColumn col= new DataColumn();
col.ColumnName = "StudentId";
col.MaxLength = 255;
// Add the column to the datatable
mydatatable.Columns.Add(col);

Read more: http://feeds.dzone.com/~r/dzone/snippets/~3/uIhVU793dkY/14603

 
Create a datacolumn which automatically increments the value of the column for new rows added to the table
Tuesday, 31 January 2012 09:57
following code will add a datacolumn which automatically increments the value of the column for new rows added to the table


DataColumn newcolumn=new DataColumn("studentID", System.Type.GetType("System.Int32"));
newcolumn.AutoIncrement = true;
newcolumn.AutoIncrementSeed = 1;
newcolumn.AutoIncrementStep = 1;

//// Add column to datatable.
DataTable mytable=new DataTable();
mytable.Columns.Add(column);

Read more: http://feeds.dzone.com/~r/dzone/snippets/~3/aGvq9wdqBdw/14593

 
Create a datacolumn which indicates whether null values are allowed in this column for rows that belong to the table or not.
Tuesday, 31 January 2012 09:54
Following code will create a studentID column that allow null values in this column for rows that belong to the this table.


DataColumn newcolumn=new DataColumn("studentID", System.Type.GetType("System.Int32"));
newcolumn.AllowDBNull = true;
//// Add column to datatable.
DataTable mytable=new DataTable();
mytable.Columns.Add(column);

Read more: http://feeds.dzone.com/~r/dzone/snippets/~3/N0LLlGPiW7s/14591

 
Bind dropwdown in gridview
Friday, 27 January 2012 10:39
// Bind dropwdown in gridview


protected void GvTestGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataTable dtData= new DataTable();
dtData= GetData(); // Get your data to be binded to dropdown
DropDownList ddlFileData= (DropDownList)e.Row.FindControl("DdlFileData");
ddlFileData.Datasource = dtData;
ddlFileData.DataBind();
}
}

Read more: http://feeds.dzone.com/~r/dzone/snippets/~3/8kmY2oCEQr8/14477

 
Select Unique records based on specified fields or column from DataTable
Monday, 19 December 2011 02:18
This will help you only when you have to filter distinct records based on specified fields.
e.g. I have a table called UserDetail which contains the following fields:

UserID | Name | Mobile | Email | City | State

Now I want to only display distinct records with Name, City and State, then you can use:

string[] TobeDistinct = {"Name","City","State"};
DataTable dtDistinct = GetDistinctRecords(DTwithDuplicate, TobeDistinct);

//Following function will return Distinct records for Name, City and State column.
public static DataTable GetDistinctRecords(DataTable dt, string[] Columns)
{
DataTable dtUniqRecords = new DataTable();
dtUniqRecords = dt.DefaultView.ToTable(true, Columns);
return dtUniqRecords;
}

Read more: http://feeds.dzone.com/~r/dzone/snippets/~3/b62ajuXbh28/14235

 


Taxonomy by Zaragoza Online