//DefaultView:filter a limited number of columns from a table:
//Distinct Data in DataTable with the Field of roleid,roleName,abbreviation........
DataSet infoDS=new DataSet();
DataTable dTable = infoDS.Tables[0].DefaultView.ToTable(true, "roleid", "roleName", "abbreviation");
for (int i = 0; i < dTable.Rows.Count; i++)
{
if (dTable.Rows.Count > 0)
{
string _RoleId = dTable.Rows[i]["roleid"].ToString();
string _RoleName = dTable.Rows[i]["roleName"].ToString();
string _Abbreviation = dTable.Rows[i]["abbreviation"].ToString();
}
}
Tuesday, January 11, 2011
Compute with DataTable
DataTable Dtable=new DataTable();
DataColumn DColumn=new DataColumn("Salary",typeof(float));
DTable.Column.Add(DColumn);
DataRow DRow=DTable.NewRow();
DRow[0]=25000;
DTable.Rows.Add(DRow);
DRow=DTable.NewRow();
DRow[0]=30000;
DTable.Rows.Add(DRow);
float TotalSalary=(float)DTable.Compute("Sum(Salary)","");
Console.WriteLine(TotalSalary);
DataColumn DColumn=new DataColumn("Salary",typeof(float));
DTable.Column.Add(DColumn);
DataRow DRow=DTable.NewRow();
DRow[0]=25000;
DTable.Rows.Add(DRow);
DRow=DTable.NewRow();
DRow[0]=30000;
DTable.Rows.Add(DRow);
float TotalSalary=(float)DTable.Compute("Sum(Salary)","");
Console.WriteLine(TotalSalary);
Labels:
Compute with DataTable
Subscribe to:
Posts (Atom)