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!

Query String 1

Status
Not open for further replies.

asafb

Programmer
Jun 17, 2003
80
US
Hello, how do you create an aspx page with a query string i.e. test.aspx?id=5,
where basically the datalist would retrieve the data just for that record. i did it in asp, but i need help to do it in .net. thanks guys!


<%@ 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 myConnection As SqlConnection
Dim myCommand As SqlDataAdapter
Dim id

id=request.querystring("id")

' Connect to the SQL database using a SQL SELECT query to get
' all the data from the "data" table.
myConnection = New SqlConnection("server=XXXX;" _
& "database=XXXX;user id=sa;pwd=XXXX")

myCommand = New SqlDataAdapter("SELECT * FROM data WHERE id = " @id ,myConnection)
^^^ this doesn't work!!!! is it @id, or & id?

' Create and fill a DataSet.
Dim ds As Dataset = new DataSet()
myCommand.Fill(ds)
' Bind MyRepeater to the DataSet. MyRepeater is the ID of the
' Repeater control in the HTML section of the page.
mydatalist.DataSource = ds
Mydatalist.DataBind()

End SUb

</script>
<html>
<head>
</head>
<body>
<asp:DataList id="mydatalist" runat="server" Width="100%" CellPadding="3" cellspacing="3" RepeatColumns="4">
<itemtemplate>
<p align="center">
<a href="estore/scripts/prodview.asp?idproduct=<%# DataBinder.Eval(Container.DataItem, ("idProduct"))%>">
<asp:Image id="Image1" runat="server" src='<%# DataBinder.Eval(Container.DataItem, ("smallimageurl"))%>'></asp:Image>
<br />
<font face="Verdana" style="font-size: 9pt; font-weight: 700"> <%# DataBinder.Eval(Container.DataItem, ("description"))%> </font></a></font></a><font face="Verdana" style="font-size: 9pt; font-weight: 700">
<br />
$<%# DataBinder.Eval(Container.DataItem, ("price"))%>
<br />
<font face="Verdana" style="font-size: 9pt; font-weight: 300"><%# DataBinder.Eval(Container.DataItem, ("descriptionLong"))%>
</itemtemplate>
</asp:DataList>
</body>
</html>
 
Here is an example....

Dim myConnection As SqlConnection
Dim myCommand As SqlCommand

Dim ds As DataSet = New DataSet
Dim id As Int16 = 10256

myConnection = New SqlConnection("server=(local);" & "database=northwind;user id=sa;pwd=sa")
myConnection.Open()

'Set up command object
myCommand = New SqlCommand("SELECT * FROM Orders WHERE Orderid = " & id, myConnection)

'You need a data adapter
Dim da As New SqlDataAdapter

da.SelectCommand = myCommand

da.Fill(ds, "Table Name")
Console.WriteLine(ds.Tables(0).Rows.Count)

da.Dispose()
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top