473,395 Members | 1,341 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

looping through a datatable

This is a question I'm carrying over from a previous one I made today
since I've simplified where the problem is...

I have a datatable, tblFeatures, which has around 30 columns (one for
each 'feature').

I also have between 1 and 3 rows of data (one for each 'vehicle').

I want to transpose this table so that I ouput the rows horizontally
and the columns vertically.

I'm looping through the datatable and manually creating the HTML as I
progress.. e.g.

Dim colFeatures As DataColumn
Dim rowFeatures As DataRow

Dim sOutputFeatures As System.Text.StringBuilder = New
System.Text.StringBuilder

For Each colFeatures In tblFeatures.Columns

sOutputFeatures.Append("<TR>")
sOutputFeatures.Append("<TD>" & colFeatures.ColumnName & "</TD>")

For Each rowFeatures In tblFeatures.Rows

sOutputFeatures.Append("<TD>" & rowFeatures(colFeatures) & "</TD>")
Next

sOutputFeatures.Append("</TR>")
Next

Response.Write sOutputFeatures.ToString()
but for some reason .. this is outputting 29 empty <TD></TD> for each
row value that it outputs.

I think I may be using the wrong syntax around the:
'For Each rowFeatures In tblFeatures.Rows' for loop

Does anyone know the proper syntax I should be using here?

Thanks in advance!
Peter
--

"I hear ma train a comin'
.... hear freedom comin"

Nov 19 '05 #1
5 3350
> Does anyone know the proper syntax I should be using here?

Maybe DataBinding?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Complex things are made up of
Lots of simple things.

"Stimp" <re*@spumco.com> wrote in message
news:sl****************@carbon.redbrick.dcu.ie...
This is a question I'm carrying over from a previous one I made today
since I've simplified where the problem is...

I have a datatable, tblFeatures, which has around 30 columns (one for
each 'feature').

I also have between 1 and 3 rows of data (one for each 'vehicle').

I want to transpose this table so that I ouput the rows horizontally
and the columns vertically.

I'm looping through the datatable and manually creating the HTML as I
progress.. e.g.

Dim colFeatures As DataColumn
Dim rowFeatures As DataRow

Dim sOutputFeatures As System.Text.StringBuilder = New
System.Text.StringBuilder

For Each colFeatures In tblFeatures.Columns

sOutputFeatures.Append("<TR>")
sOutputFeatures.Append("<TD>" & colFeatures.ColumnName & "</TD>")

For Each rowFeatures In tblFeatures.Rows

sOutputFeatures.Append("<TD>" & rowFeatures(colFeatures) & "</TD>")
Next

sOutputFeatures.Append("</TR>")
Next

Response.Write sOutputFeatures.ToString()
but for some reason .. this is outputting 29 empty <TD></TD> for each
row value that it outputs.

I think I may be using the wrong syntax around the:
'For Each rowFeatures In tblFeatures.Rows' for loop

Does anyone know the proper syntax I should be using here?

Thanks in advance!
Peter
--

"I hear ma train a comin'
... hear freedom comin"

Nov 19 '05 #2
you need to have two loops one for Rows and another nested loop for columns.
Still databinding is the best option you can use datagrid or datalist(
datagridview in case of asp.net 2.0)
regards
Nitin
"Stimp" <re*@spumco.com> wrote in message
news:sl****************@carbon.redbrick.dcu.ie...
This is a question I'm carrying over from a previous one I made today
since I've simplified where the problem is...

I have a datatable, tblFeatures, which has around 30 columns (one for
each 'feature').

I also have between 1 and 3 rows of data (one for each 'vehicle').

I want to transpose this table so that I ouput the rows horizontally
and the columns vertically.

I'm looping through the datatable and manually creating the HTML as I
progress.. e.g.

Dim colFeatures As DataColumn
Dim rowFeatures As DataRow

Dim sOutputFeatures As System.Text.StringBuilder = New
System.Text.StringBuilder

For Each colFeatures In tblFeatures.Columns

sOutputFeatures.Append("<TR>")
sOutputFeatures.Append("<TD>" & colFeatures.ColumnName & "</TD>")

For Each rowFeatures In tblFeatures.Rows

sOutputFeatures.Append("<TD>" & rowFeatures(colFeatures) & "</TD>")
Next

sOutputFeatures.Append("</TR>")
Next

Response.Write sOutputFeatures.ToString()
but for some reason .. this is outputting 29 empty <TD></TD> for each
row value that it outputs.

I think I may be using the wrong syntax around the:
'For Each rowFeatures In tblFeatures.Rows' for loop

Does anyone know the proper syntax I should be using here?

Thanks in advance!
Peter
--

"I hear ma train a comin'
... hear freedom comin"

Nov 19 '05 #3
On Fri, 11 Nov 2005 Nitin <si******@gmail.com> wrote:
you need to have two loops one for Rows and another nested loop for columns.
Still databinding is the best option you can use datagrid or datalist(
datagridview in case of asp.net 2.0)
hmmm.. ok I'll try to continue with hackin away at it.

Databinding isn't an option since I need to transpose the data

regards
Nitin
"Stimp" <re*@spumco.com> wrote in message
news:sl****************@carbon.redbrick.dcu.ie...
This is a question I'm carrying over from a previous one I made today
since I've simplified where the problem is...

I have a datatable, tblFeatures, which has around 30 columns (one for
each 'feature').

I also have between 1 and 3 rows of data (one for each 'vehicle').

I want to transpose this table so that I ouput the rows horizontally
and the columns vertically.

I'm looping through the datatable and manually creating the HTML as I
progress.. e.g.

Dim colFeatures As DataColumn
Dim rowFeatures As DataRow

Dim sOutputFeatures As System.Text.StringBuilder = New
System.Text.StringBuilder

For Each colFeatures In tblFeatures.Columns

sOutputFeatures.Append("<TR>")
sOutputFeatures.Append("<TD>" & colFeatures.ColumnName & "</TD>")

For Each rowFeatures In tblFeatures.Rows

sOutputFeatures.Append("<TD>" & rowFeatures(colFeatures) & "</TD>")
Next

sOutputFeatures.Append("</TR>")
Next

Response.Write sOutputFeatures.ToString()
but for some reason .. this is outputting 29 empty <TD></TD> for each
row value that it outputs.

I think I may be using the wrong syntax around the:
'For Each rowFeatures In tblFeatures.Rows' for loop

Does anyone know the proper syntax I should be using here?

Thanks in advance!
Peter
--

"I hear ma train a comin'
... hear freedom comin"


--

"I hear ma train a comin'
.... hear freedom comin"

Nov 19 '05 #4
> Databinding isn't an option since I need to transpose the data

Of course Databinding is an option. Just transpose the data into a bindable
object and databind to that.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
There's a seeker born every minute.
- Dr. "Happy" Harry Cox

"Stimp" <re*@spumco.com> wrote in message
news:sl****************@carbon.redbrick.dcu.ie...
On Fri, 11 Nov 2005 Nitin <si******@gmail.com> wrote:
you need to have two loops one for Rows and another nested loop for
columns.
Still databinding is the best option you can use datagrid or datalist(
datagridview in case of asp.net 2.0)


hmmm.. ok I'll try to continue with hackin away at it.

Databinding isn't an option since I need to transpose the data

regards
Nitin
"Stimp" <re*@spumco.com> wrote in message
news:sl****************@carbon.redbrick.dcu.ie...
This is a question I'm carrying over from a previous one I made today
since I've simplified where the problem is...

I have a datatable, tblFeatures, which has around 30 columns (one for
each 'feature').

I also have between 1 and 3 rows of data (one for each 'vehicle').

I want to transpose this table so that I ouput the rows horizontally
and the columns vertically.

I'm looping through the datatable and manually creating the HTML as I
progress.. e.g.

Dim colFeatures As DataColumn
Dim rowFeatures As DataRow

Dim sOutputFeatures As System.Text.StringBuilder = New
System.Text.StringBuilder

For Each colFeatures In tblFeatures.Columns

sOutputFeatures.Append("<TR>")
sOutputFeatures.Append("<TD>" & colFeatures.ColumnName & "</TD>")

For Each rowFeatures In tblFeatures.Rows

sOutputFeatures.Append("<TD>" & rowFeatures(colFeatures) & "</TD>")
Next

sOutputFeatures.Append("</TR>")
Next

Response.Write sOutputFeatures.ToString()
but for some reason .. this is outputting 29 empty <TD></TD> for each
row value that it outputs.

I think I may be using the wrong syntax around the:
'For Each rowFeatures In tblFeatures.Rows' for loop

Does anyone know the proper syntax I should be using here?

Thanks in advance!
Peter
--

"I hear ma train a comin'
... hear freedom comin"


--

"I hear ma train a comin'
... hear freedom comin"

Nov 19 '05 #5
On Sat, 12 Nov 2005 Kevin Spencer <ke***@DIESPAMMERSDIEtakempis.com> wrote:
Databinding isn't an option since I need to transpose the data


Of course Databinding is an option. Just transpose the data into a bindable
object and databind to that.


nah.. I've used the following code and it's working perfectly..

For Each colFeatures In tblFeatures.Columns

sOutputFeatures.Append("<TR>")
sOutputFeatures.Append("<TD>" & colFeatures.ColumnName & "</TD>")

For Each rowFeatures In tblFeatures.Rows

If Not rowFeatures(colFeatures) Is DBNull.Value Then
sOutputFeatures.Append("<TD>" &
rowFeatures(colFeatures) & "</TD>")
End If
Next

sOutputFeatures.Append("</TR>")
Next
cheers!
--

"I hear ma train a comin'
.... hear freedom comin"

Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Kelvin | last post by:
Hi All, How to get column value from datarow while datatable looping ? Please advised !
4
by: Kelvin | last post by:
Dear All, Please help. Same as subject !!!
1
by: Kelvin | last post by:
Hi All, I wrote a program insert new row between rows while the datatable is looping. It display the error message. Exception Details: System.ArgumentException: This row already belongs to this...
1
by: Kelvin | last post by:
Hi All, While the existing datatable is looping, I can insert new row into datatable, but I can't insert it between datarows. All new rows will inserted into buttom row. Please advise!
0
by: Kelvin | last post by:
Hi All, Due to can't insert new row between row and row while current DataTable looping. In order to solve the problem, I need to clone it as new DataTable, while the DataTable Looping, it also...
5
by: Richard | last post by:
Windows Forms, csharp, 20 rows in DataTable 14 shown in view after filter applied. For any of the 14 how do I do the datarow or something else thing to access the data in the row of the table...
2
by: Roy | last post by:
Hi all, I do have a datatable that looks like: id Number Description 1 1 Desc1 2 1 Desc2 3 2 Desc3 I need this datatable looks like (with 4 rows...
7
by: Ken | last post by:
Hi All - I have a filtered GridView. This GridView has a check box in the first column. This check box is used to identify specific rows for delete operations. On the button click event I...
2
by: =?Utf-8?B?Sm9iIExvdA==?= | last post by:
How can I reconcile changes between two data table and create a subset of those changes. I have two data tables with same schema which gets populated from two different xml files. I want to get...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.