|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
||||
|
||||
|
ASP.Net/VB.Net - I'm stuck with help from a book
I'm going through this book called build your own asp.net website using C# and VB.Net and he put together an example page for reading from a access database, however i am using an SQL database and he really doesn't give a good example of how that. So anyway i built the code on the page, but when i run the page it just displays the page and not my data. So i'm not seeing any errors, just no data. Is my connection string setup wrong?? Are my queries setup wrong? I have no clue.
Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="index.vb" Inherits="index" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Dorknozzle Intranet</title>
<link href="style.css" rel="stylesheet" />
<script runat="server" language="vbscript">
Sub Page_Load()
Dim objConn As SqlConnection
Dim objCmd As SqlCommand
Dim objRdr As SqlDataReader
objConn = New SqlConnection("Data Source=WEB_SERVER;Inital Catalog=intranet;User ID=dbaccess;Password=4231")
objCmd = New SqlCommand("Select * FROM employees", objConn)
objConn.Open()
objRdr = objCmd.ExecuteReader()
rpcEmpDirectory.DataSource = objRdr
rpcEmpDirectory.DataBind()
objRdr.Close()
objConn.Close()
End Sub
</script>
</head>
<body leftmargin="0" marginheight="0" marginwidth="0" topmargin="0">
<form runat="server">
<table width="100%" border="0" cellspacing="0" cellpadding="0" background="images/header_bg.gif">
<tr>
<td>
<img src="images/header_top.gif" width="450" height="142" alt="the official dorknozzle company intranet" />
</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="175"><img src="images/header_bottom.gif" width="157" height="37" alt="" />
</td>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top" width="160">
<img src="images/book_closed.gif" alt="+" />
<asp:HyperLink NavigateUrl="~/index.aspx" runat="server" Text="Home"></asp:HyperLink>
<br />
<img src="images/book_closed.gif" alt="+" />
<asp:HyperLink ID="HyperLink2" NavigateUrl="~/helpdesk.aspx" runat="server" Text="HelpDesk"></asp:HyperLink>
<br />
<img src="Images/book_closed.gif" alt="+" />
<asp:HyperLink ID="HyperLink3" NavigateUrl="~/employeestore.aspx" runat="server" Text="Employee Store"></asp:HyperLink>
<br />
<img src="Images/book_closed.gif" alt="+" />
<asp:HyperLink ID="HyperLink4" NavigateUrl="~/newsletterarchive.aspx" runat="server" Text="Newsletter Archive"></asp:HyperLink>
<br />
<img src="Images/book_closed.gif" alt="+" />
<asp:HyperLink ID="HyperLink5" NavigateUrl="~/employeedirectory.aspx" runat="server" Text="Employee Directory"></asp:HyperLink>
<br />
<img src="Images/book_closed.gif" alt="+" />
<asp:HyperLink ID="HyperLink6" NavigateUrl="~/addressbook.aspx" runat="server" Text="Address Book"></asp:HyperLink>
<br />
<img src="Images/book_closed.gif" alt="+" />
<asp:HyperLink ID="HyperLink7" NavigateUrl="~/admintools.aspx" runat="server" Text="Admin Tools"></asp:HyperLink>
<br />
</td>
<td valign="top">
<h1>Employee Directory</h1>
<asp:Repeater ID="rpcEmpDirectory" runat="server">
<ItemTemplate>
<p>Employee ID: <strong>
<%# Container.DataItem("EmployeeID") %><br /></strong>
Name: <strong>
<%# Container.DataItem("Name") %></strong><br />
Extension: <strong>
<%# Container.DataItem("Extension") %></strong></p>
</ItemTemplate>
<SeparatorTemplate><hr noshade="noshade" size="1" />
</SeparatorTemplate>
</asp:Repeater>
</td>
</tr>
</table>
</form>
</body>
</html>
|
|
#2
|
||||
|
||||
|
Not sure if this would cause your issue or not, but one thing I see missing that is in most of my SqlConnections is: Security Info=True;
So: Code:
objConn = New SqlConnection("Data Source=WEB_SERVER;Inital Catalog=intranet;Security Info=True;User ID=dbaccess;Password=4231")
It was just a brief scan of your code though, so let me know if that doesn't fix it and I'll dig a little deeper.
__________________
It should be noted that no ethically-trained software engineer would ever consent to write a DestroyBaghdad procedure. Basic professional ethics would instead require him to write a DestroyCity procedure, to which Baghdad could be given as a parameter. (Nathaniel S Borenstein) |
|
#3
|
||||
|
||||
|
Quote:
i added that, i still get a page full of content, but nothing from my database, and no errors. And yes, there is records in my tables. |
|
#4
|
||||
|
||||
|
I got it to work when I changed Sub Page_Load() to
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load |
|
#5
|
||||
|
||||
|
Quote:
ok.. i tried it, still no results. i'm confused Code:
<script runat="server" language="vbscript">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim objConn As SqlConnection
Dim objCmd As SqlCommand
Dim objRdr As SqlDataReader
objConn = New SqlConnection("Data Source=WEB_SERVER;Inital Catalog=intranet;User ID=dbaccess;Password=4231;Security Info=True;")
objCmd = New SqlCommand("Select * FROM employees", objConn)
objConn.Open()
objRdr = objCmd.ExecuteReader()
rpcEmpDirectory.DataSource = objRdr
rpcEmpDirectory.DataBind()
objRdr.Close()
objConn.Close()
End Sub
</script>
how do i know if my database connection is working? |
|
#6
|
||||
|
||||
|
It would give you an error if it wasn't, saying it couldn't find the server or whatnot. This is the code I used and it worked fine - you'll notice the only things I changed were mentioned above, the sub line and also the database/tables so it would actually pull data for me (I obviously don't have your database). It's a copy and paste of yours with a few changes.
I also changed the repeater to show items that corresponded to the stuff I pulled form a database. I'm pretty sure I didn't change anything else, but copy this code, paste it and make the adjustments to your repeater and your database connection and see if it works for you. Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="test.aspx.vb" Inherits="test" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Dorknozzle Intranet</title>
<link href="style.css" rel="stylesheet" />
<script runat="server" language="vbscript">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim objConn As SqlConnection
Dim objCmd As SqlCommand
Dim objRdr As SqlDataReader
objConn = New SqlConnection("Data Source=SqlServer\SQLExpress;Initial Catalog=***;Persist Security Info=True;User ID=**;Password=***")
objCmd = New SqlCommand("Select * FROM WorkoutPerson", objConn)
objConn.Open()
objRdr = objCmd.ExecuteReader()
rpcEmpDirectory.DataSource = objRdr
rpcEmpDirectory.DataBind()
objRdr.Close()
objConn.Close()
End Sub
</script>
</head>
<body leftmargin="0" marginheight="0" marginwidth="0" topmargin="0">
<form id="Form1" runat="server">
<table width="100%" border="0" cellspacing="0" cellpadding="0" background="images/header_bg.gif">
<tr>
<td>
<img src="images/header_top.gif" width="450" height="142" alt="the official dorknozzle company intranet" />
</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="175"><img src="images/header_bottom.gif" width="157" height="37" alt="" />
</td>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top" width="160">
<img src="images/book_closed.gif" alt="+" />
<asp:HyperLink ID="HyperLink1" NavigateUrl="~/index.aspx" runat="server" Text="Home"></asp:HyperLink>
<br />
<img src="images/book_closed.gif" alt="+" />
<asp:HyperLink ID="HyperLink2" NavigateUrl="~/helpdesk.aspx" runat="server" Text="HelpDesk"></asp:HyperLink>
<br />
<img src="Images/book_closed.gif" alt="+" />
<asp:HyperLink ID="HyperLink3" NavigateUrl="~/employeestore.aspx" runat="server" Text="Employee Store"></asp:HyperLink>
<br />
<img src="Images/book_closed.gif" alt="+" />
<asp:HyperLink ID="HyperLink4" NavigateUrl="~/newsletterarchive.aspx" runat="server" Text="Newsletter Archive"></asp:HyperLink>
<br />
<img src="Images/book_closed.gif" alt="+" />
<asp:HyperLink ID="HyperLink5" NavigateUrl="~/employeedirectory.aspx" runat="server" Text="Employee Directory"></asp:HyperLink>
<br />
<img src="Images/book_closed.gif" alt="+" />
<asp:HyperLink ID="HyperLink6" NavigateUrl="~/addressbook.aspx" runat="server" Text="Address Book"></asp:HyperLink>
<br />
<img src="Images/book_closed.gif" alt="+" />
<asp:HyperLink ID="HyperLink7" NavigateUrl="~/admintools.aspx" runat="server" Text="Admin Tools"></asp:HyperLink>
<br />
</td>
<td valign="top">
<h1>Employee Directory</h1>
<asp:Repeater ID="rpcEmpDirectory" runat="server">
<ItemTemplate>
<p>Employee ID: <strong>
<%#Container.DataItem("WorkoutPersonID")%><br /></strong>
Name: <strong>
<%#Container.DataItem("WorkoutPerson")%></strong><br />
Extension:</p>
</ItemTemplate>
<SeparatorTemplate><hr noshade="noshade" size="1" />
</SeparatorTemplate>
</asp:Repeater>
</td>
</tr>
</table>
</form>
</body>
|
|
#7
|
||||
|
||||
|
Quote:
ok thank you. i had to do some more modifications but i finally got it to work. solution Code:
<script runat="server" language="vbscript">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim objConn As SqlConnection
Dim objCmd As SqlCommand
Dim objRdr As SqlDataReader
objConn = New SqlConnection("Data Source=WEB_SERVER;Database=intranet;User ID=sa;Password=4231;")
objCmd = New SqlCommand("Select * FROM employees", objConn)
objConn.Open()
objRdr = objCmd.ExecuteReader()
rpcEmpDirectory.DataSource = objRdr
rpcEmpDirectory.DataBind()
objRdr.Close()
objConn.Close()
End Sub
</script>
|
![]() |
| Viewing: ASP Free Forums > Programming > .NET Development > ASP.Net/VB.Net - I'm stuck with help from a book |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
![]() |
|