Thursday, January 31, 2013

Convert DataTable into a String


Following method will convert a DataTable into a string in the format of:

Column Header Name:-:Cell Value##Column Header Name:-:Cell Value##Column Header Name:-:Cell Value.....

public string DataTabletoString(DataTable DT)
{
  StringBuilder SB = new StringBuilder();
foreach (DataRow rowItem in DT.Rows)
{
foreach (DataColumn colItem in DT.Columns)
{
  SB.Append(colItem.ToString()+":- :"+rowItem[colItem].ToString()+"##");
}
}
  return SB.ToString();
}

No comments:
Write comments
Recommended Posts × +