AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 String builder
Posted by chotoapa on  7/8/2010 9:05:29 PM Category: VB.NET
Add to my favorites
Email to friend
Hi,
I am using string builder to convert datatable to string. I am pulling data from dataset. How to loop through in datarow for each column.

My code is
For Each dr As DataRow In adt.GetDataBydate(startdate)
For i= 0 to 4 ( I wanna use it here "For each" loop for checking column and i wanna show it in a label control)
builder.Append(dr.Item(i))
lblissue.Text = builder.ToString()

Format would be like this:
Startdate Enddate city region
20/10/2009 22/10/2009 DA GAT

How to read row and column and append it to the string builder?

Post Your Reply Post New Question

 Viewer's Reply
Looping through DataTable Rows and Columns
Answered By Moderator1 on 7/12/2010 10:03:24 AM
Hi,

Use the below code for looping through DataRow and DataColumns.

string sql = "Select * from customers";
SqlDataAdapter da = new SqlDataAdapter(sql, cnstr);
DataTable dt = new DataTable();
da.Fill(dt);

foreach (DataRow dr in dt.Rows)
{
foreach (DataColumn dc in dt.Columns)
{
Response.Write(dc.ColumnName + "=" + dr[dc.ColumnName].ToString());

}

Response.Write("<br />");
}
 
Post Your Reply If you still have problem, post it again under this reply for better response.

 
Sponsored by
Windows 8: 50 Questions and Answers You Need to Make a Decision (Normally $9.95)
Easing the Migration to Microsoft SQL Server 2005
Everything You Know About CSS Is Wrong! - Free 37 Page Preview!