Thursday

datatable copy c#

here is procedure for copying data b/w different fields in two tables
         
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:

imagemagic add text to image

rem different types of text annotations on existing images rem cyan yellow orange gold rem -gravity SouthWest rem draw text and anno...