Hello everyone:

I wrote the following routine to convert a datatable to a string.
However, I am wondering if this is the most efficient way of doing it
in .NET.

private static string DataTableToString(DataTable table, string delimiter)
{
  if (table.Rows.Count == 0) {return String.Empty;}
  StringBuilder buffer = new StringBuilder();

  foreach (DataRow row in table.Rows)
  {
    object[] items = row.ItemArray;
    foreach(object obj in items)
    {
      buffer.Append(obj.ToString());
      buffer.Append(delimiter);
    }

  buffer.Remove(buffer.Length - delimiter.Length,delimiter.Length);
  buffer.Append("\r");
  buffer.Append("\n");
  }

  buffer.Remove(buffer.Length - 2,2);
  return buffer.ToString();
}

thanks, Greg

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to