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:

test smtp server with powershell

Send-MailMessage -SMTPServer smtp.domain.com -To [email protected] -From [email protected] -Subject "This is a test email" -Body ...