public DataTable CopyData(DataTable indata, Hashtable fields)
{
DataTable ret = new DataTable();
foreach (string k in fields.Keys)
{
ret.Columns.Add((string)fields[k], indata.Columns[k].DataType);
}
foreach (DataRow row in indata.Rows)
{
DataRow dr = ret.NewRow();
foreach (string k in fields.Keys)
{
dr[(string)fields[k]] = String.Format("{0}", row[k]);
}
ret.Rows.Add(dr);
}
return ret;
}
create mapping b/w fields in original table and result table and call procedure
Hashtable fieldsMap= new Hashtable()
{
{"[Measures].[Week]","Week"},
{"[Measures].[Month]","Month"},
{"[Measures].[Quarter]","Quarter"},
{"[Measures].[Year]","Year"},
};
// call copy data procedure
DataTable result = CopyData(OriginaldataTable, fieldsMap);
more...
No comments:
Post a Comment