473,385 Members | 1,542 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,385 software developers and data experts.

Looping through related data..?

Usually, If i need special formatting, I don't use the datagrid control and
use a loop that processes a table for each record read from the database (as
in classic asp) like so:

================================================== ==========

Dim strSQL, strResults As String
Dim objConnection As SqlConnection
Dim objCommand As SqlCommand
Dim objDataReader As SqlDataReader

strResults = ""

strSQL = "SELECT ID, ClientID, Field, Form, Employee, username,"
& _
" ip, probdt, Descript, isnotes, noshow FROM TProblem" &
_
" WHERE ((TProblem.noshow)= NO) ORDER BY ID DESC;"

objConnection = New
SqlConnection(ConfigurationManager.AppSettings("ti ckets"))
objCommand = New SqlCommand(strSQL, objConnection)

objConnection.Open()
objDataReader = objCommand.ExecuteReader()

Do While objDataReader.Read() = True
strResults += "<table cellpadding=""5"" cellspacing=""0""
border=""1"" bordercolor=""maroon"" width=""95%""><tr>"
strResults += "<td bgcolor=""red"" width=""10%""><b>ID:<br
/><font color=""white"">" & objDataReader("ID").ToString &
"</font></b></td>"
strResults += "<td bgcolor=""silver""
width=""30%""><b>Client ID:</b><br />" & objDataReader("ClientID").ToString
& "</td>"
strResults += "<td bgcolor=""silver""
width=""30%""><b>Field:</b><br />" & objDataReader("Field").ToString &
"</td>"
strResults += "<td bgcolor=""silver""
width=""30%""><b>Form:</b><br />" & objDataReader("Form").ToString & "</td>"

strResults += "</tr><tr>"

strResults += "<td bgcolor=""silver""
width=""10%""><b>Employee Name:<br /><font color=""navy"">" &
objDataReader("Employee").ToString & "</font></b></td>"
strResults += "<td bgcolor=""silver""
width=""30%""><b>Username:</b><br />" & objDataReader("username").ToString &
"</td>"
strResults += "<td bgcolor=""silver"" width=""30%""><b>IP
Address:</b><br />" & objDataReader("ip").ToString & "</td>"
strResults += "<td bgcolor=""silver""
width=""30%""><b>Date/Time:</b><br />" & objDataReader("probdt").ToString &
"</td>"

strResults += "</tr><tr>"

strResults += "<td colspan=""4""><b>Description:</b><br />"
& objDataReader("Descript").ToString & "</td>"
strResults += "</tr><tr>"
strResults += "<td colspan=""4""><b>HHS Info Systems
Notes:</b><br />" & objDataReader("isnotes").ToString & "<br /></td>"
strResults += "</tr></table>"
strResults += "<br />"
Loop
objDataReader.Close()
objConnection.Close()
datagrid1.InnerHTML = strResults
================================================== ==========

I've not worked with related data much so trying to figure out my current
problem is a tough challenge for me.

I have two tables. The second of the table has a foregin key that is linked
to the primary key of the first table. The PK of the first table is auto
incremented (identity field)

My project, simply, is to display a table that displays data posted by our
employess that shows who they are and what their computer problem is along
with date, active directory username and IP. Then, the IT staff has a
seperate page that we view these problems on. From this page we also need to
be able to post messages to each individula employee posted problem so that
each message that we post (comment) is shown within the same html table
showing the employee's computer issue. That's what the related table is for,
so we have one row in the first table (the data that the employee posts) and
many related rows in the second table (our comments we post for each single
post from the employee).

Now, doing a loop to create an html table within the browser window for a
single data table isn't hard, as I show above. But, how would I go about
this with two related tables? I was thinking another loop within the loop to
loop through the related records and create the appropriate <tr>s and <td>s,
but I don't know how to make the relation.

Help! :)

Thanks,
Jim
Nov 19 '05 #1
2 1470
"Jim in Arizona" <ti*******@hotmail.com> wrote in
news:Oz**************@TK2MSFTNGP14.phx.gbl:
Usually, If i need special formatting, I don't use the datagrid
control and use a loop that processes a table for each record read
from the database (as in classic asp) like so:

Hmmm... you should seriously consider using a datagrid. Take a look at
the OnItemDataBound event.

Or at the least... use some ASP.NET objects (i.e. Table, TableCell,
TableRow)...

================================================== ==========

Dim strSQL, strResults As String
Dim objConnection As SqlConnection
Dim objCommand As SqlCommand
Dim objDataReader As SqlDataReader

strResults = ""

strSQL = "SELECT ID, ClientID, Field, Form, Employee,
username,"
& _
" ip, probdt, Descript, isnotes, noshow FROM
TProblem" &
_
" WHERE ((TProblem.noshow)= NO) ORDER BY ID DESC;"

objConnection = New
SqlConnection(ConfigurationManager.AppSettings("ti ckets"))
objCommand = New SqlCommand(strSQL, objConnection)

objConnection.Open()
objDataReader = objCommand.ExecuteReader()

Do While objDataReader.Read() = True
strResults += "<table cellpadding=""5""
cellspacing=""0""
border=""1"" bordercolor=""maroon"" width=""95%""><tr>"
strResults += "<td bgcolor=""red""
width=""10%""><b>ID:<br
/><font color=""white"">" & objDataReader("ID").ToString &
"</font></b></td>"
strResults += "<td bgcolor=""silver""
width=""30%""><b>Client ID:</b><br />" &
objDataReader("ClientID").ToString & "</td>"
strResults += "<td bgcolor=""silver""
width=""30%""><b>Field:</b><br />" & objDataReader("Field").ToString &
"</td>"
strResults += "<td bgcolor=""silver""
width=""30%""><b>Form:</b><br />" & objDataReader("Form").ToString &
"</td>"

strResults += "</tr><tr>"

strResults += "<td bgcolor=""silver""
width=""10%""><b>Employee Name:<br /><font color=""navy"">" &
objDataReader("Employee").ToString & "</font></b></td>"
strResults += "<td bgcolor=""silver""
width=""30%""><b>Username:</b><br />" &
objDataReader("username").ToString & "</td>"
strResults += "<td bgcolor=""silver""
width=""30%""><b>IP
Address:</b><br />" & objDataReader("ip").ToString & "</td>"
strResults += "<td bgcolor=""silver""
width=""30%""><b>Date/Time:</b><br />" &
objDataReader("probdt").ToString & "</td>"

strResults += "</tr><tr>"

strResults += "<td
colspan=""4""><b>Description:</b><br />"
& objDataReader("Descript").ToString & "</td>"
strResults += "</tr><tr>"
strResults += "<td colspan=""4""><b>HHS Info Systems
Notes:</b><br />" & objDataReader("isnotes").ToString & "<br /></td>"
strResults += "</tr></table>"
strResults += "<br />"
Loop
objDataReader.Close()
objConnection.Close()
datagrid1.InnerHTML = strResults
================================================== ==========


--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 19 '05 #2
Indeed. I'll second the OnItemDataBound suggestion. At the least, you
should look into the Repeater.

Even in classic ASP, I wouldn't go down the road you're travelling
except in extreme cases. And then I'd spin off a couple objects to
break it into managable chunks. But mostly, that kind of string
building went out with Perl & ISAPI.

Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/

Nov 19 '05 #3

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

Similar topics

8
by: kaptain kernel | last post by:
i've got a while loop thats iterating through a text file and pumping the contents into a database. the file is quite large (over 150mb). the looping causes my CPU load to race up to 100 per...
2
by: ensnare | last post by:
Hi all, I'm using a database session handler and am looking to loop through data residing in the sessions table to make a 'Users online' array. I've found that using urldecode on the data...
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...
13
by: JayCallas | last post by:
I know this question has been asked. And the usual answer is don't use cursors or any other looping method. Instead, try to find a solution that uses set-based queries. But this brings up...
6
by: Luke - eat.lemons | last post by:
Hi, Im pretty new to asp so all light on this question would be great. Basically i need to test to see what value is set (where to retrieve the data from) so ive done it like this: If...
3
by: Luke - eat.lemons | last post by:
Sorry for the post in this NG but im short on time to get this working and i haven't seem to of got a response anywhere else. Im pretty new to asp so all light on this question would be great. ...
67
by: gator | last post by:
I am quite new to XML and posted a request for example code yesterday. Unfortunately, I did not do a very good job in explaining what I was looking for. Here is an example of a small piece of the...
6
by: mahowe | last post by:
Hi, I have had this problem for a while and have not been able solve it. What im looking at doing is looping thru my patient table and trying to organise the patients in to there admission...
7
by: Tom Davis | last post by:
I am having a problem where a long-running function will cause a memory leak / balloon for reasons I cannot figure out. Essentially, I loop through a directory of pickled files, load them, and run...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.