Convert Dataset into String
6 Comments so far
Leave a comment
October 20, 2008, 5:17 am
Filed under: Uncategorized | Tags: ASP.NET C#, Dataset, DataTable, Handler, String
Filed under: Uncategorized | Tags: ASP.NET C#, Dataset, DataTable, Handler, String
This function can be use to convert dataset into string format in Handler file.
private String DatasetToString(DataSet ds)
{
Int32 i = 0;
String str = “”;
DataTable dt = ds.Tables[0];
while (i < dt.Rows.Count)
{
str += “;” + dt.Rows[i][1].ToString() + “;” + dt.Rows[i][0].ToString();
i++;
}
return (str);
}
Advertisement
6 Comments so far
Leave a comment
Hi Buddy!!!!
Comment by Prashant October 20, 2008 @ 11:41 amIt is such a Nice tip
Dude,
Comment by Brook Oldre March 22, 2009 @ 9:39 pmYou rock!
This was such a pain in my @#@ and your code fixed it!!!
Thanks
Allah razı olsun
Comment by onur May 28, 2009 @ 6:01 amthat’s a good approach.
Comment by chetan.sharma June 19, 2009 @ 5:19 amIt would be MUCH more efficent to create a stringbuilder in “convert dataset into string” and append the rows onto the sb. If you use concatenation, every time the new data is concatenated, a copy of the string is made with the new data appended.
Comment by Bob Levittan October 23, 2009 @ 5:13 pmprivate string DatasetToString(DataSet ds)
{
StringBuilder sb = new StringBuilder();
DataTable dt = ds.Tables(0);
foreach (DataRow dr in dt.Rows) {
sb.Append(“;”);
sb.Append(dt.Rows(1).ToString());
}
return sb.ToString();
}
Comment by Bob Levittan October 23, 2009 @ 5:25 pm