Anirudh’s Weblog


Convert Dataset into String
October 20, 2008, 5:17 am
Filed under: Uncategorized | Tags: , , , ,
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!!!!
It is such a Nice tip

Comment by Prashant

Dude,
You rock!
This was such a pain in my @#@ and your code fixed it!!!
Thanks

Comment by Brook Oldre

Allah razı olsun :D

Comment by onur

that’s a good approach.

Comment by chetan.sharma

It 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

private 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




Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s



Follow

Get every new post delivered to your Inbox.