Listing 1. connectionFactory.vb Friend Class connectionFactory Private msConnectionString As String Public Sub New(ByVal ConnectionString As String) msConnectionString = ConnectionString End Sub Public Sub New() msConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=R: \VisualStudioNetProjects\CompanyEvents\events.mdb" End Sub Friend Function getConnection() As OleDb.OleDbConnection Dim oConnection As New OleDb.OleDbConnection(msConnectionString) oConnection.Open() Return oConnection End Function End Class Listing 2. eventCommands.vb Friend Class eventCommands Public Function getEventsForDateHTML(ByVal eventDate As Date, ByVal OleConn As OleDb.OleDbConnection) As DataTable Dim oDataSet As DataSet Dim oDTable As System.Data.DataTable Dim oDRow As System.Data.DataRow oDataSet = getEventsbyDate(eventDate, OleConn) Return oDataSet.Tables(0) End Function Private Function getEventsbyDate(ByVal eventDate As Date, ByVal OleConn As OleDb.OleDbConnection) As DataSet Dim oDataSet As New DataSet("Events") Dim oAdapt As New OleDb.OleDbDataAdapter() Dim sQuery As String sQuery = "Select * from tblEvents where EventDate = #" & eventDate.ToString & "#" oAdapt.SelectCommand = New OleDb.OleDbCommand(sQuery, OleConn) oAdapt.Fill(oDataSet) Return oDataSet End Function Public Function getCategories(ByVal OleConn As OleDb.OleDbConnection) As DataTable Dim oDataSet As New DataSet("Categories") Dim oDSTable As DataTable, oDRow As System.Data.DataRow Dim oAdapt As New OleDb.OleDbDataAdapter() Dim sQuery As String, sOut As String oAdapt.SelectCommand = New OleDb.OleDbCommand("Select iCategoryID, Category from tblCategories order by Category", OleConn) oAdapt.Fill(oDataSet, "Categories") Return oDataSet.Tables(0) End Function Public Function getEventsByDateAndCategoryID(ByVal eventDate As Date, ByVal catID As Integer, ByVal OleConn As OleDb.OleDbConnection) As DataTable Dim oDataSet As New DataSet("Events") Dim oAdapt As New OleDb.OleDbDataAdapter() Dim sQuery As String sQuery = "Select * from tblEvents where EventDate = #" & eventDate & "# and CategoryID =" & catID oAdapt.SelectCommand = New OleDb.OleDbCommand(sQuery, OleConn) oAdapt.Fill(oDataSet) Return oDataSet.Tables(0) End Function End Class Listing 3. Events.vb Public Class Events 'The Event Class gets the user or app what they need Private oconnFactory As New connectionFactory("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\visualStudioHome\CompanyEvents\events.mdb") Public Function getEventsHTML(ByVal dt As Date) As String Dim oconn As OleDb.OleDbConnection = oconnFactory.getConnection() Dim oEventCommands As New eventCommands() Dim oDTable As DataTable = oEventCommands.getEventsForDateHTML(dt, oconn) Return createHTMLEventTable(oDTable) End Function Public Function getEventsByCategoryHTML(ByVal dtEvent As Date, ByVal iCat As Integer) As String Dim oconn As OleDb.OleDbConnection = oconnFactory.getConnection() Dim oEventCommands As New eventCommands() Dim oDTable As DataTable = oEventCommands.getEventsByDateAndCategoryID(dtEvent, iCat, oconn) Return createHTMLEventTable(oDTable) End Function Public Function getCategoryOptionList() As String Dim oconn As OleDb.OleDbConnection = oconnFactory.getConnection() Dim oEventCommands As New eventCommands() Dim oDSTable As DataTable = oEventCommands.getCategories(oconn) Dim oDRow As DataRow Dim sOut As String sOut = vbNullString For Each oDRow In oDSTable.Rows sOut &= "" Next oconn.Close() Return sOut End Function Private Function createHTMLEventTable(ByVal EventDataTable As DataTable) As String Dim strOut As String strOut = "" Dim oDRow As DataRow For Each oDRow In EventDataTable.Rows strOut &= "" strOut &= "" strOut &= "" strOut &= "" strOut &= "" Next strOut &= "
" & oDRow.Item("EventDate") & "" & oDRow.Item("EventName") & "" & oDRow.Item("EventSponsor") & "
" oDRow = Nothing EventDataTable = Nothing Return strOut End Function End Class Listing 4. - Web Service Code Imports System.Web.Services Public Class Service1 Inherits System.Web.Services.WebService #Region " Web Services Designer Generated Code " Public Function EventCategoryOptions() As String Dim oEvents As New CompanyEvents.Events() EventCategoryOptions = oEvents.getCategoryOptionList() End Function Public Function getEventsByDate(ByVal EventDate As Date) As String Dim oEvents As New CompanyEvents.Events() getEventsByDate = oEvents.getEventsHTML(EventDate) End Function Public Function getEvntsByDateAndCat(ByVal EventDate As Date, ByVal Category As Integer) As String Dim oEvents As New CompanyEvents.Events() getEvntsByDateAndCat = oEvents.getEventsByCategoryHTML(EventDate, Category) End Function End Class