I get the following error when I try to run either mine or your code using Visual Basic .NET Version 7.1.3088
I have tried altering field names in the database like Status to _Status, but that hasn't helped.
Everything is great using Web Matrix but when I incorporate it into my
VB.NET this is the error.
The code I'm using follows error message. Thanks in advance for any help you can offer.
DeeDee
Source Error:
Line 66: dbCommand.Parameters.Add(dbParam_teamID)
Line 67: dbConnection.Open()
Line 68: Dim dr As IDataReader = dbCommand.ExecuteReader(CommandBehavior.CloseConne ction)
Line 69: Return dr
Line 70: End Function
Source File: C:\Inetpub\wwwroot\Ch10WroxUnitedApp\Teams.aspx.
vb Line: 68
Stack Trace:
[OleDbException (0x80004005): IErrorInfo.GetDescription failed with E_FAIL(0x80004005).]
System.Data.OleDb.OleDbCommand.ExecuteCommandTextE rrorHandling(Int32 hr)
System.Data.OleDb.OleDbCommand.ExecuteCommandTextF orSingleResult(tagDBPARAMS dbParams, Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteCommandText( Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteCommand(Comm andBehavior behavior, Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteReaderIntern al(CommandBehavior behavior, String method)
System.Data.OleDb.OleDbCommand.ExecuteReader(Comma ndBehavior behavior)
System.Data.OleDb.OleDbCommand.System.Data.IDbComm and.ExecuteReader(CommandBehavior behavior)
Ch10WroxUnitedApp.WebForm2.GetPlayersByTeam(Int32 teamID) in C:\Inetpub\wwwroot\Ch10WroxUnitedApp\Teams.aspx.
vb :68
Ch10WroxUnitedApp.WebForm2.TeamList_ItemCommand(Ob ject sender, DataListCommandEventArgs e) in C:\Inetpub\wwwroot\Ch10WroxUnitedApp\Teams.aspx.
vb :75
System.Web.UI.WebControls.DataList.OnItemCommand(D ataListCommandEventArgs e)
System.Web.UI.WebControls.DataList.OnBubbleEvent(O bject source, EventArgs e)
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
System.Web.UI.WebControls.DataListItem.OnBubbleEve nt(Object source, EventArgs e)
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
System.Web.UI.WebControls.LinkButton.OnCommand(Com mandEventArgs e)
System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
System.Web.UI.Page.ProcessRequestMain()
teams.aspx
<%@ Page Language="
vb" AutoEventWireup="false" Codebehind="Teams.aspx.
vb" Inherits="Ch10WroxUnitedApp.WebForm2"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
</HEAD>
<body>
<form runat="server" ID="Form2">
<h1>Wrox United
</h1>
<h2>Teams
</h2>
<p>
<table>
<tbody>
<tr>
<td>
<asp:DataList id="TeamList" runat="server" OnItemCommand="TeamList_ItemCommand">
<ItemTemplate>
<asp:linkbutton text='<%# Container.DataItem("TeamName") %>' CommandArgument='<%# Container.DataItem("TeamID") %>' id="TeamNameLink" style="color:darkred" runat="server" CommandName="ShowTeam" />
<br />
<asp:Label text='<%# Container.DataItem("Notes") %>' id="teamnotes" runat="server" />
</ItemTemplate>
<SeparatorTemplate>
<br />
</SeparatorTemplate>
</asp:DataList>
</td>
<td style="VERTICAL-ALIGN: top">
<asp:Repeater id="PlayersList" runat="server">
<ItemTemplate>
<asp:linkbutton text='<%# Container.DataItem("PlayerName") %>' style="color:darkred" runat="server" width="120" ID="Linkbutton1"/>
<asp:Label text='<%# Container.DataItem("PositionName") %>' id="playerposition" runat="server" />
<br />
</ItemTemplate>
<headerTemplate>
Players in:
<%= selectedTeam %>
</headerTemplate>
<footerTemplate>
</footerTemplate>
</asp:Repeater>
</td>
</tr>
</tbody>
</table>
</p>
</form>
</body>
</HTML>
Teams.aspx.
vb
Option Strict Off
Imports System.Data
Imports System.Data.OleDb
Public Class WebForm2
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents conn As System.Data.OleDb.OleDbConnection
Protected WithEvents TeamList As System.Web.UI.WebControls.DataList
Protected WithEvents PlayersList As System.Web.UI.WebControls.Repeater
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Public SelectedTeam As String
Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TeamList.DataSource = GetTeams()
TeamList.DataBind()
End Sub
Function GetTeams() As System.Data.IDataReader
Dim conn As String = ConfigurationSettings.AppSettings("ConnectionStrin g")
Dim dbConnection As IDbConnection = New OleDbConnection(conn)
Dim query As String = "SELECT Teams.TeamID, Teams.TeamName, Teams.Notes " & _
"FROM Teams"
Dim dbCommand As IDbCommand = New OleDbCommand
dbCommand.CommandText = query
dbCommand.Connection = dbConnection
dbConnection.Open()
Dim dr As IDataReader = dbCommand.ExecuteReader(CommandBehavior.CloseConne ction)
Return dr
End Function
Function GetPlayersByTeam(ByVal teamID As Integer) As IDataReader
Dim conn As String = ConfigurationSettings.AppSettings("ConnectionStrin g")
Dim dbConnection As IDbConnection = New OleDbConnection(conn)
Dim query As String = "SELECT Players.PlayerName, Positions.PositionName" & _
"FROM Players, Positions, PlayerTeam, Teams" & _
"WHERE ((PlayerTeam.PlayerID = Players.PlayerID)" & _
"AND (PlayerTeam.Position = Positions.PositionID)" & _
"AND (PlayerTeam.TeamID = Teams.TeamID)" & _
"AND (PlayerTeam.TeamID = @TeamID))"
Dim dbCommand As IDbCommand = New OleDbCommand
dbCommand.CommandText = query
dbCommand.Connection = dbConnection
Dim dbParam_teamID As IDataParameter = New OleDbParameter
dbParam_teamID.ParameterName = "@TeamID"
dbParam_teamID.Value = teamID
dbParam_teamID.DbType = DbType.Int32
dbCommand.Parameters.Add(dbParam_teamID)
dbConnection.Open()
Dim dr As IDataReader = dbCommand.ExecuteReader(CommandBehavior.CloseConne ction)
Return dr
End Function
Sub TeamList_ItemCommand(ByVal sender As Object, ByVal e As DataListCommandEventArgs)
If e.CommandName.Equals("ShowTeam") Then
SelectedTeam = CType(e.CommandSource, LinkButton).Text
PlayersList.DataSource = GetPlayersByTeam(e.CommandArgument)
PlayersList.DataBind()
End If
End Sub
End Class
web.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="ConnectionString"
value="Provider=Microsoft.Jet.OLEDB.4.0; Ole Db Services=-4; Data Source=C:\Inetpub\wwwroot\Copy of WroxUnited.mdb" />
</appSettings>
<system.web>
<!-- DYNAMIC DEBUG COMPILATION
Set compilation debug="true" to insert debugging symbols (.pdb information)
into the compiled page. Because this creates a larger file that executes
more slowly, you should set this value to true only when debugging and to
false at all other times. For more information, refer to the documentation about
debugging ASP.NET files.
-->
<compilation defaultLanguage="
vb" debug="true" />
<!-- CUSTOM ERROR MESSAGES
Set customErrors mode="On" or "RemoteOnly" to enable custom error messages, "Off" to disable.
Add <error> tags for each of the errors you want to handle.
"On" Always display custom (friendly) messages.
"Off" Always display detailed ASP.NET error information.
"RemoteOnly" Display custom (friendly) messages only to users not running
on the local Web server. This setting is recommended for security purposes, so
that you do not display application detail information to remote clients.
-->
<customErrors mode="RemoteOnly" />
<!-- AUTHENTICATION
This section sets the authentication policies of the application. Possible modes are "Windows",
"Forms", "Passport" and "None"
"None" No authentication is performed.
"Windows" IIS performs authentication (Basic, Digest, or Integrated Windows) according to
its settings for the application. Anonymous access must be disabled in IIS.
"Forms" You provide a custom form (Web page) for users to enter their credentials, and then
you authenticate them in your application. A user credential token is stored in a cookie.
"Passport" Authentication is performed via a centralized authentication service provided
by Microsoft that offers a single logon and core profile services for member sites.
-->
<authentication mode="Windows" />
<!-- AUTHORIZATION
This section sets the authorization policies of the application. You can allow or deny access
to application resources by user or role. Wildcards: "*" mean everyone, "?" means anonymous
(unauthenticated) users.
-->
<authorization>
<allow users="*" />
<!-- <allow users="[comma separated list of users]"
roles="[comma separated list of roles]"/>
<deny users="[comma separated list of users]"
roles="[comma separated list of roles]"/>
-->
</authorization>
<!-- APPLICATION-LEVEL TRACE LOGGING
Application-level tracing enables trace log output for every page within an application.
Set trace enabled="true" to enable application trace logging. If pageOutput="true", the
trace information will be displayed at the bottom of each page. Otherwise, you can view the
application trace log by browsing the "trace.axd" page from your web application
root.
-->
<trace enabled="false" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true" />
<!-- SESSION STATE SETTINGS
By default ASP.NET uses cookies to identify which requests belong to a particular session.
If cookies are not available, a session can be tracked by adding a session identifier to the URL.
To disable cookies, set sessionState cookieless="true".
-->
<sessionState
mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
cookieless="false"
timeout="20"
/>
<!-- GLOBALIZATION
This section sets the globalization settings of the application.
-->
<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
</system.web>
</configuration>