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!

ASP.NET page not displaying SQL data

Status
Not open for further replies.

DanOoo

Programmer
Feb 26, 2005
15
US
I have an ASP.NET user control page and codebehind page that have a code problem that is not displaying in the trace. The page loads fine without errors but does not pull the database information. Any help with the included code would be greatly appreciated.
Thank you,
Dan

--------------------------------------------------------
CodeBehind Page:

Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HTMLControls
Imports System.Collections
Imports System.Data.SqlClient
Imports System.Text.RegularExpressions
Imports Microsoft.VisualBasic

Public Class TrucksCodeBehind

Inherits Page

Protected conLocal As String = "Server=Local;UID=Guest;PWD=Password;Database=SQLDB"
Protected cmdSelectTrucks As SqlCommand
Protected dtrTrucks As SqlDataReader
Protected cmdSelectTrucks As SqlCommand


Sub Page_Load()

Dim conLocal As SqlConnection
Dim cmdSelectTrucks As SqlCommand
Dim dtrTrucks As SqlDataReader
Dim urlID = Request.QueryString("ID")

conLocal = New SqlConnection( "Server=Local;UID=Guest;PWD=Password;Database=SQLDB" )
conLocal.Open()
cmdSelectTrucks = New SqlCommand( "SELECT Make, Model, Year, Color, Engine FROM Trucks WHERE UID = " &urlID, conLocal )
dtrTrucks = cmdSelectTrucks.ExecuteReader()

While dtrTrucks.Read
lblMake.text = dtrTrucks("Make")
lblModel.text = dtrTrucks("Model")
lblYear.text = dtrTrucks("Year")
lblColor.text = dtrTrucks("Color")
lblEngine.text = dtrTrucks("Engine")
End While

dtrTrucks.Close()
dtrTrucks = Nothing
conLocal.Close()
conLocal = Nothing

End Sub

End Class

----------------------------------------------------
User Control Page:

<%@ Control Language="vb" AutoEventWireup="false" Codebehind="Trucks.ascx.vb"%>

<table cellpadding="0" cellspacing="0" border="0" bordercolor="#000000" align="center">
<TR>
<td class="Content"><asp:label id="lblMake" Runat="server">Make: &nbsp;</asp:label><% Response.Write("Make") %></td>
</TR>
<TR>
<td class="Content"><asp:label id="lblModel" Runat="server">Model: &nbsp;</asp:label><% Response.Write("Model") %></td>
</TR>
<TR>
<td class="Content"><asp:label id="lblYear" Runat="server">Year: &nbsp;</asp:label><% Response.Write("Year") %></td>
</TR>
<TR>
<td class="Content"><asp:label id="lblColor" Runat="server">Color: &nbsp;</asp:label><% Response.Write("Color") %></td>
</TR>
<TR>
<td class="Content"><asp:label id="lblEngine" Runat="server">Engine: &nbsp;</asp:label><% Response.Write("Engine") %></td>
</TR>
</table>
 
And what happens in your While Loop when you debug it? Does it go into the loop (i.e. is a record returned)?

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
ca8msm,

Thank you for responding. The page loads and appears to be running through the loop and then displays the page without generating an errors or returning the records. Debug and trace do not return any errors either.
I get the following instead of the records.

Make: Make
Model: Model
Year: Year
Color: Color
Engine: Engine
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top