473,548 Members | 2,604 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Str ingBuilder = New
System.Text.Str ingBuilder

For Each colFeatures In tblFeatures.Col umns

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

For Each rowFeatures In tblFeatures.Row s

sOutputFeatures .Append("<TD>" & rowFeatures(col Features) & "</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.Row s' 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 3361
> 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.i e...
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.Str ingBuilder = New
System.Text.Str ingBuilder

For Each colFeatures In tblFeatures.Col umns

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

For Each rowFeatures In tblFeatures.Row s

sOutputFeatures .Append("<TD>" & rowFeatures(col Features) & "</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.Row s' 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.i e...
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.Str ingBuilder = New
System.Text.Str ingBuilder

For Each colFeatures In tblFeatures.Col umns

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

For Each rowFeatures In tblFeatures.Row s

sOutputFeatures .Append("<TD>" & rowFeatures(col Features) & "</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.Row s' 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.i e...
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.Str ingBuilder = New
System.Text.Str ingBuilder

For Each colFeatures In tblFeatures.Col umns

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

For Each rowFeatures In tblFeatures.Row s

sOutputFeatures .Append("<TD>" & rowFeatures(col Features) & "</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.Row s' 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.i e...
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.i e...
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.Str ingBuilder = New
System.Text.Str ingBuilder

For Each colFeatures In tblFeatures.Col umns

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

For Each rowFeatures In tblFeatures.Row s

sOutputFeatures .Append("<TD>" & rowFeatures(col Features) & "</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.Row s' 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***@DIESPAMM ERSDIEtakempis. 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.Col umns

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

For Each rowFeatures In tblFeatures.Row s

If Not rowFeatures(col Features) Is DBNull.Value Then
sOutputFeatures .Append("<TD>" &
rowFeatures(col Features) & "</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
25497
by: Kelvin | last post by:
Hi All, How to get column value from datarow while datatable looping ? Please advised !
4
34590
by: Kelvin | last post by:
Dear All, Please help. Same as subject !!!
1
22527
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 table. System.Data.DataTable.InsertRow(DataRow row, Int32 proposedID, Int32 pos) +319 System.Data.DataRowCollection.Add(DataRow row) +14
1
2195
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
5822
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 insert both of new row and existing datarow into new DataTable, but I don't know how to do that, Here is my souce code, Please advise. if (...
5
1928
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 behind the view selected on the datagrid. DataGrid only gives an index based on the 1-14 visible on the datagrid and I can't seem to update anything I...
2
2455
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 which the third one is blank): id Number Description 1 1 Desc1 2 1 Desc2
7
5461
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 loop through the filtered GridView to identify the selected rows and assemble some XML to be sent to a stored proc. The problem I have is that when...
2
2481
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 hold of missing & changed rows in first table from second table. Tables have ID as primary key. Thanks
0
7512
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7707
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7951
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7466
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5362
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5082
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3475
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1051
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
751
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.