Click to See Complete Forum and Search --> : A question about data retrieval


juicemousezero
09-09-2005, 10:58 AM
I was wondering how I could take the data from my dataset and store the different rows and columns in variables so that I could put them where I want on my ASP.NET page. I did it in PHP using this syntax:


$i = 0;
while ($i < $rows)
{
$id = mysql_result($result, $i, "id");
$bandname = mysql_result($result, $i, "bandname");
$cdtitle = mysql_result($result, $i, "cdtitle");
$yearmade = mysql_result($result, $i, "yearmade");
$cdreview = mysql_result($result, $i, "cdreview");

echo "$id<br>$bandname<br>$cdtitle<br>$yearmade<br>$cdreview<br><br>";
$i = $i +1;
}


That way I can toss, say, the CD review variable anywhere I need to on the page and not even use the other data if I don't see fit. I'm trying to figure out that same thing except in VB.NET syntax and I'm not sure how to go about it... thanks guys.

Cstick
09-09-2005, 09:50 PM
This is nearly verbatim to your code:

'Ds is your dataset.
'This assumes that your dataset has only 1 table and that table
'is already filled with your data.

Dim strItem1(Ds.Tables(0).Rows.Count) As String
Dim strItem2(Ds.Tables(0).Rows.Count) As String
Dim strItem3(Ds.Tables(0).Rows.Count) As String

For Each Dr As System.Data.DataRow in Ds.Tables(0).Rows
strItem1(idx) = Dr.Item("SomeColumnName1")
strItem2(idx) = Dr.Item("SomeColumnName2")
strItem3(idx) = Dr.Item("SomeColumnName3")

response.write(strItem1(idx) & "<br />" & strItem2(idx) & "<br />" & strItem3(idx) & "<br /><br />")
Next


However there is no need to create the string arrays, you could have just have easily done this:

'Ds is your dataset.
'This assumes that your dataset has only 1 table and that table
'is already filled with your data.

For Each Dr As System.Data.DataRow in Ds.Tables(0).Rows
response.write(Dr.Item("SomeColumnName1") & "<br />" & Dr.Item("SomeColumnName2") & "<br />" & Dr.Item("SomeColumnName3") & "<br /><br />")
Next

juicemousezero
09-10-2005, 12:12 AM
Thanks a lot man. That does indeed seem to be what I want to do. I really appreciate the help. I dunno if I would have figured it out on my own. :D

Thanks again!