ASP.Net and Data access

G

Guest

I have developed in ASP in the past and am now getting into ASP.Net and have
hit a road block. I've been reading tutorias and documents and am still
having problems. I have the following code example:

****************************************

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter

MyConnection = New
SqlConnection("server=sqlserver;database=sales;Trusted_Connection=Yes")
MyCommand = New SqlDataAdapter("select * from orders where orderid =
32000", MyConnection)

DS = New DataSet
MyCommand.Fill(DS, "Orders")

Repeater2.DataSource = DS
Repeater2.DataBind()


End Sub



<%@ Page Language="vb" AutoEventWireup="false" Codebehind="orders.aspx.vb"%>
<HTML>
<HEAD>
<title>orders</title>
</HEAD>
<body>
<form runat="server">
<asp:Repeater id="Repeater2" runat="server">
<HeaderTemplate>
<Table width="100%" style="font: 8pt verdana">

<tr>
<th>
Order ID
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%# DataBinder.Eval(Container.DataItem, "OrderID") %>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater></TD>
</form>
</body>
</HTML>

************************************************


This code looks good to me but when I run this, I do not get anything on the
page (blank). Here is the html after I run it:


<HTML>
<HEAD>
<title>orders</title>
</HEAD>
<body>
<form name="_ctl0" method="post" action="orders.aspx" id="_ctl0">
<input type="hidden" name="__VIEWSTATE"
value="dDw1NzE5OTAzNTI7Oz6dpCg+ix9Yj9gsw5NbtgI82h5suw==" />

</TD>
</form>
</body>
</HTML>


I just cant understand why I am not getting any data.

Any help would be much appreciated.
 
G

Guest

Try setting the DataSource to the Orders Table in the dataset instead of the
dataset object itself.
 
J

Juan T. Llibre

Is there an "orderid" field which has
an orderID value of 32000 ?

That's what you're requesting.

If a record with the value "32000" in the "orderID"
field doesn't exist, there's nothing to display.




Juan T. Llibre
ASP.NET MVP
===========
 
G

Guest

This was just an example. I was tring to retrieve some other fields also but
I still get nothing. This record does exist in the database.
 
T

Terri Morton

Check your data again. I took your exact code, just changed the connection
string to the Northwind database, and the OrderID to 10270, and it all works
just fine (ie a record is returned and the ID appears on my screen).

Terri
MVP - ASP/ASP.NET
 
J

Juan T. Llibre

You beat me to that by a few minutes. :)

10270 WARTH 1 01/08/1996 29/08/1996 02/08/1996 1 136.54 Wartian Herkku Torikatu 38 Oulu 90110 Finland

There's nothing wrong with that code.
I did the same as you to test Paul's code.

Here's the complete code used :


<%@ Page Language="vb" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<HTML>
<HEAD>
<title>orders</title>
<script language="vb" runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter
MyConnection = New SqlConnection("Server=MySQLServer;Integrated Security=True;Database=Northwind")
MyCommand = New SqlDataAdapter("select * from orders where orderid = 10270", MyConnection)
DS = New DataSet
MyCommand.Fill(DS, "Orders")
Repeater2.DataSource = DS
Repeater2.DataBind()
End Sub
</script>
</HEAD>
<body>
<form id="Form1" runat="server">
<asp:Repeater id="Repeater2" runat="server">
<HeaderTemplate>
<Table width="100%" style="font: 8pt verdana">
<tr>
<th>
Order ID
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%# DataBinder.Eval(Container.DataItem, "OrderID") %>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater></TD>
</form>
</body>
</HTML>




Juan T. Llibre
ASP.NET MVP
===========
 
G

Guest

The data is fine. The record exists. I tried pointing this code to the
Northwind database also with the same result. I also tried pointing it to a
Time Tracker database (sample ASP.NET app download from MS) and still nothing
(even though the Time Tracker app works fine).

Can't understand why this does not work.
 
T

Terri Morton

Are you recompiling your code before you try it out in the browser?

Juan's code below does not involve a code-behind file, so it would be
compiled automatically before being brought up in the browser. But the code
you originally supplied involves a code-behind file and would require
compilation.

Terri Morton
MVP - ASP/ASP.NET
 
J

Juan T. Llibre

Do you get any error messages ?
If so, what do they say ?



Juan T. Llibre
ASP.NET MVP
===========
 
T

Terri Morton

For grins, can you take the exact code posted by Juan, save it as test.aspx,
put that in your web folder, try it out in your browser, and let us kow what
you see?

Terri Morton
MVP - ASP/ASP.NET
 
G

Guest

There must have been an issue with the form itself. I created a new Web Form
and copied the code over and it works now.

Really weird but the issue is gone now.

Thanks to all for your input.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top