473,728 Members | 1,919 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 3371
> 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
25569
by: Kelvin | last post by:
Hi All, How to get column value from datarow while datatable looping ? Please advised !
4
34638
by: Kelvin | last post by:
Dear All, Please help. Same as subject !!!
1
22549
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
2207
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
5831
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 ( myTable.Rows.Count > 0 )
5
1932
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 see in the dataview quickwatch that I can update the underlying row. I could manually keep track...
2
2477
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
5471
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 looping through the GridView, it doesn't
2
2500
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
8903
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8758
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9277
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9198
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8129
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6013
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4524
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3236
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2161
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.