Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieve a SPECIFIC row using dataset

Status
Not open for further replies.

asafblasberg

Programmer
Jun 22, 2004
21
US
Hello, how do I retrieve data for a specific row using a dataset. I want to fetch the 3rd row information.

<%@ Page Language="VB" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">
protected test as string

Sub Page_Load(sender As Object, e As EventArgs)
Dim myconnection3 As SqlConnection
Dim myda As SqlDataAdapter
Dim ds As DataSet
dim strconn as string
strConn = ConfigurationSettings.AppSettings("o")
myconnection3 = New SqlConnection(strConn)

'If there are options in our option group, then show them and
'populate the results in the drop down list.

'retrieve options from the option groups.
myda = New SqlDataAdapter("SELECT categorydesc from categories", myconnection3)

ds = New DataSet()
myda.Fill(ds, "categories")

HELP!! Now, I want to take the third row's data and display the data in the column "CategoryDesc" of the "category" table

then, assign it to a protected variable called ASAF
end sub


</script>
<html>
<head>
</head>
<body>
<form ID="test" runat="server">
STRING IS: <%# test %>
<asp:Label id="asaflabel" Runat="server"></asp:Label>
</form>

</body>
</html>
 
asa: I'm still a bit handicapped at the moment, being between computers, etc, and re-settling. There is indeed a property of datasets which allows you to loop through the dataset by row, or find directly the row itself.

Unfortunetly my books & notes are not readily handy but I would suggest you find a good source on ADO.NET on the web (or a book) and most of them walk directly through the various properties one can use with DataSets.

DataSets may have their drawbacks re: scalibility but they may be cached, saved to the disk, sorted, searched, you name it -- their ability to be cached on the Client side also opens up many opportunities.

If you can find a good source on ADO.NET you will enjoy the read -- the DataSets are quite entertaining. Sorry I can't remember off hand specifically what the properties were -- but I do remember they are simple enough.

Also do a quick Search at Tek-Tips. We have discussed many times DataSets and there should be several examples out there. Good Luck.
 
You can access the rows of a table within a dataset as a collection as you would the values in an array. YOu can access the rows and cells either by name or using an integer index. I have used 2 to acces the 3rd row as collections are zero-based.
Code:
ASAF = ds.Tables("Categories").Rows(2)("CategoryDesc").ToString()

Rob

Every gun that is made, every warship launched, every rocket fired, signifies in the final sense a theft from those who hunger and are not fed, those who are cold and are not clothed - Eisenhower 1953
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top