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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataReader Specific Value

Status
Not open for further replies.

asafb

Programmer
Jun 17, 2003
80
US
Hello,

I have a datareader which binds my datalist. Now, I want to fetch Row #21 lets say and store the data that is in a specific column called "Sound" to a variable. Anyway to do this?

<%@ Page Language="vb" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
' Create a connection to the "pubs" SQL database located
' on the local computer.
Dim strConn as String

dim id, string1
id=request.querystring("id")


string1 = Help!!!


strConn = "server=x;" _
& "database=x;user id=x;pwd=x"
Dim MySQL as string = "SELECT * FROM products" Dim MyConn as New SQLConnection(strConn)
Dim objDR as SQLDataReader

Dim Cmd as New SQLCommand(MySQL, MyConn)
MyConn.Open()
objDR=Cmd.ExecuteReader()
MyDataList.DataSource = objDR
MyDataList.DataBind()
End Sub
</script>
<body>
<asp:DataList id="mydatalist" HorizontalAlign="Center" cssclass = "wcrussmall" halign="center" ItemStyle-VerticalAlign="Top" itemstyle-horizontalalign= "Center" ItemStyle-Width = "250" repeatlayout="table" cellpadding="4" CellSpacing="2" runat="server">

<asp:Image id="Image1" runat="server" src='<%# DataBinder.Eval(Container.DataItem, ("smallimageurl"))%>'>
</asp:Image

<%# DataBinder.Eval(Container.DataItem, ("description"))%><br>
<%# DataBinder.Eval(Container.DataItem, ("descriptionLong"))%></a></font></a><br>
List Price: <%# DataBinder.Eval(Container.DataItem, ("listprice"), "{0:c}")%><br>Our Price: <%# DataBinder.Eval(Container.DataItem, ("price"), "{0:c}")%><br>

</itemtemplate>

</asp:DataList></body>
 
Code:
SqlDataReader dr;

for( int i = 0; i < 21; i++ )
   dr.Read();

int i = Convert.ToInt32( dr["Sound"] );

If you want to keep track during the DataBinding process, look to the ItemDataBound event.
 
hello boudlerbum, thank you, but can you give me that code in vb.net not c?
thanks
asaf
 
Picky, picky.

It's something like this:

Code:
Dim dr As SqlDataReader

Dim i As Integer

For i = 0 To 21
   dr.Read()
Next 

Dim sound As Integer
sound = Convert.ToInt32( dr("Sound") )
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top