I was following the module development exercise in the book "Building Websites with VB.NET and DotNetNuke 4" by Daniel N. Egan, Michael Washington, and Steve Valenzuela. It was the chapter (Chapter 8) on "Connecting to the Database" that my site got killed.
I followed all the instructions & used the code I downloaded from the publisher's web site. The files CoffeeShopListingOptionsController.vb, Settings.ascx, and Settings.ascx.vb cannot be compiled successfully due to some errors/problems the codes in them. Since I don't know enough of the language VB.NET and how to utilize it for database connection, I am stuck and can't fix the bugs. I hope someone can help me (or someone who has read the book and know about the exercise/tutorial).
Here is the code and the corresponding errors in the 3 files:
--------------------------------------------------------------
FILE: CoffeeShopListingOptionsController.vb
<CODE>
Imports System
Imports System.Data
Imports System.Collections.Generic
Namespace EganEnterprises.CoffeeShopListing
Public Class CoffeeShopListingOptionsController
Public Function EganEnterprises_GetCoffeeShopModuleOptions(ByVal ModuleId As Integer) As List(Of CoffeeShopListingOptionsInfo)
Return CBO.FillCollection(Of CoffeeShopListingOptionsInfo)(CType(DotNetNuke.Data.DataProvider.Instance().ExecuteReader("EganEnterprises_GetCoffeeShopModuleOptions", ModuleId), IDataReader))
End Function
Public Function EganEnterprises_UpdateCoffeeShopModuleOptions(ByVal objShopListOptions As EganEnterprises.CoffeeShopListing.CoffeeShopListingOptionsInfo) As Integer
Return CType(DotNetNuke.Data.DataProvider.Instance().ExecuteScalar("EganEnterprises_UpdateCoffeeShopModuleOptions", objShopListOptions.moduleID, objShopListOptions.AuthorizedRoles), Integer)
End Function
Public Function EganEnterprises_AddCoffeeShopModuleOptions(ByVal objShopListOptions As EganEnterprises.CoffeeShopListing.CoffeeShopListingOptionsInfo) As Integer
Return CType(DotNetNuke.Data.DataProvider.Instance().ExecuteScalar("EganEnterprises_AddCoffeeShopModuleOptions", objShopListOptions.moduleID, objShopListOptions.AuthorizedRoles), Integer)
End Function
End Class
End Namespace
</CODE>
ERROR: DotNetNuke.Data.DataProvider.Instance().ExecuteReader
MESSAGE: 'ExecuteReader' is not a member of 'DotNetNuke.Data.DataProvider'.
ERROR: DotNetNuke.Data.DataProvider.Instance().ExecuteScalar
MESSAGE: 'ExecuteScalar' is not a member of 'DotNetNuke.Data.DataProvider'.
--------------------------------------------------------------
FILE: Settings.ascx
<CODE>
<%@ Control language="vb" AutoEventWireup="false" Inherits="EganEnterprises.CoffeeShopListing.Settings" CodeFile="Settings.ascx.vb"%>
<%@ Register TagPrefix="Portal" TagName="DualList" Src="~/controls/DualListControl.ascx" %>
<table id="Table1" cellspacing="1" cellpadding="1" width="100%" border="1">
<tr>
<td>
<p align="center">ShopListOptions</P>
</td>
</tr>
<tr>
<td><portal:duallist id="ctlAuthRoles" runat="server" ListBoxWidth="130" ListBoxHeight="130" DataValueField="Value"
DataTextField="Text" /></td>
</tr>
</table>
</CODE>
ERROR: portal:duallist
Message: Element 'duallist' is not a known element. This can occur if there is a compilation error in the web site.
--------------------------------------------------------------
FILE: Settings.ascx.vb
<CODE>
Imports DotNetNuke
Imports DotNetNuke.Security.Roles
Imports System.Web
Imports System.Collections.Generic
Imports System.Web.UI.WebControls
Namespace EganEnterprises.CoffeeShopListing
Partial Class Settings
'Inherits Entities.Modules.PortalModuleBase
Inherits DotNetNuke.Entities.Modules.ModuleSettingsBase
#Region "Base Method Implementations"
Public Overrides Sub LoadSettings()
Try
' declare roles
Dim arrAvailableAuthRoles As New ArrayList
Dim arrAssignedAuthRoles As New ArrayList
' Get list of possible roles
Dim objRoles As New RoleController
Dim objRole As RoleInfo
Dim arrRoles As ArrayList = objRoles.GetPortalRoles(PortalId)
'String of roles for shoplist
Dim objShopRoles As New CoffeeShopListingOptionsController
Dim objShopRole As CoffeeShopListingOptionsInfo
Dim arrShopRoles As List(Of CoffeeShopListingOptionsInfo) = objShopRoles.EganEnterprises_GetCoffeeShopModuleOptions(ModuleId)
'Put roles into a string
Dim shopRoles As String = ""
For Each objShopRole In arrShopRoles
'If it makes it here then we will be updating
shopRoles = objShopRole.AuthorizedRoles.ToString
Next
'Now loop through all avalible roles in portal
For Each objRole In arrRoles
Dim objListItem As New ListItem
objListItem.Value = objRole.RoleID.ToString()
objListItem.Text = objRole.RoleName.ToString()
'If it matches a role in the ShopRoles string put
'it in the assigned box
If shopRoles.IndexOf(objRole.RoleID & ";") <> -1 Or objRole.RoleID = PortalSettings.AdministratorRoleId Then
arrAssignedAuthRoles.Add(objListItem)
Else ' put it inthe avalible box
arrAvailableAuthRoles.Add(objListItem)
End If
Next
' assign to duallist controls
ctlAuthRoles.Available = arrAvailableAuthRoles
ctlAuthRoles.Assigned = arrAssignedAuthRoles
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
Public Overrides Sub UpdateSettings()
Try
Dim objShopRoles As New CoffeeShopListingOptionsController
Dim objShopRole As New CoffeeShopListingOptionsInfo
Dim item As ListItem
Dim strAuthorizedRoles As String = ""
For Each item In ctlAuthRoles.Assigned
strAuthorizedRoles += item.Value & ";"
Next item
objShopRole.AuthorizedRoles = strAuthorizedRoles
objShopRole.moduleID = ModuleId
Dim intExists As Integer
intExists = objShopRoles.EganEnterprises_UpdateCoffeeShopModuleOptions(objShopRole)
If intExists = 0 Then 'New record
objShopRoles.EganEnterprises_AddCoffeeShopModuleOptions(objShopRole)
End If
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
#End Region
End Class
End Namespace
</CODE>
ERROR: ctlAuthRoles.Available = arrAvailableAuthRoles
MESSAGE: Name 'ctlAuthRoles' is not declared.
--------------------------------------------------------------
Any assistance is appreciated. Or any advice in how to roll the site and database back to the state before this madness is extremely welcome too.
Thanks in advance!
jc