Hi all,
Im a newbie to ASP.NET and to this forum so Im not sure if Im posting this query in the correct place or not.
Basically I am doing my final piece of coursework for my ASP.NET course where I have to write a fully fledged ASP.NET e-commerce site.
I am only just starting and have written 2 .vb pages which control some simple tasks so that I dont have to write the same things over again in code.
Basically I have 2 pages of code (written in VB.NET), ‘Utilities.vb’ and ‘GenericDataAccess.vb’. I have referenced a sub-routine in in 'Utilities.vb' from 'GenericDataAccess.vb' but Visual Studio 2008 has flagged an error:
'ErrorResult is not a member of Utilities'
Im not sure what I have done wrong or why it is flagging this error. It seems to be ok to me. Im wondering if anyone can help me or tell me a better way to do what Im trying to do.
The code for both files is below:
Utilities.vb
GenericDataAccess.vb
Any help would be greatly appreciated.
Thanks in advance
-=Stylus=--
Im a newbie to ASP.NET and to this forum so Im not sure if Im posting this query in the correct place or not.
Basically I am doing my final piece of coursework for my ASP.NET course where I have to write a fully fledged ASP.NET e-commerce site.
I am only just starting and have written 2 .vb pages which control some simple tasks so that I dont have to write the same things over again in code.
Basically I have 2 pages of code (written in VB.NET), ‘Utilities.vb’ and ‘GenericDataAccess.vb’. I have referenced a sub-routine in in 'Utilities.vb' from 'GenericDataAccess.vb' but Visual Studio 2008 has flagged an error:
'ErrorResult is not a member of Utilities'
Im not sure what I have done wrong or why it is flagging this error. It seems to be ok to me. Im wondering if anyone can help me or tell me a better way to do what Im trying to do.
The code for both files is below:
Utilities.vb
VB.NET:
Imports Microsoft.VisualBasic
Imports System
Imports System.Net
Imports System.Net.Mail
Public Class Utilities
''' <summary>
''' Class contains miscellaneous functionality
''' </summary>
Public Class Utilities
Shared Sub New()
'
' TODO: Add constructor logic here
''
End Sub
' Generic method for sending emails
Public Shared Sub SendMail(ByVal txtfrom As String, ByVal txtto As String, ByVal txtsubject As String, ByVal txtbody As String)
' Configure mail client
Dim mailClient As New SmtpClient
' Create the mail message
Dim objmailMessage As New MailMessage()
' Send mail
mailClient.Send(objmailMessage)
End Sub
' Send error log mail
Public Shared Sub ErrorResult(ByVal ex As Exception)
' get the current date and time
Dim dateTimeInfo As String = DateTime.Now
' stores the error message
Dim errorMessage As String = ("Exception generated on " + dateTimeInfo)
' obtain the page that generated the error
Dim context As System.Web.HttpContext = System.Web.HttpContext.Current
errorMessage = (errorMessage + ("" & vbLf & vbLf & " Page location: " + context.Request.RawUrl))
' build the error message
errorMessage = (errorMessage + ("" & vbLf & vbLf & " Message: " + ex.Message))
errorMessage = (errorMessage + ("" & vbLf & vbLf & " Source: " + ex.Source))
errorMessage = (errorMessage + ("" & vbLf & vbLf & " Method: " + ex.GetType.ToString))
errorMessage = (errorMessage + ("" & vbLf & vbLf & " Stack Trace: " & vbLf & vbLf + ex.StackTrace))
' send error email in case the option is activated in web.config
If SIOnlineMusicShopConfiguration.EnableErrorLogEmail Then
Dim txtfrom As String = SIOnlineMusicShopConfiguration.MailFrom
Dim txtto As String = SIOnlineMusicShopConfiguration.ErrorLogEmail
Dim txtsubject As String = "SI Online Music Shop Error Report"
Dim txtbody As String = errorMessage
SendMail(txtfrom, txtto, txtsubject, txtbody)
End If
End Sub
End Class
End Class
GenericDataAccess.vb
VB.NET:
Imports System
Imports System.Data
Imports System.Data.Common
''' <summary>
''' Class contains generic data access functionality to be accessed from
''' the business tier
''' </summary>
Public Class GenericDataAccess
' static constructor
Shared Sub New()
'
' TODO: Add constructor logic here
'
End Sub
' executes a command and returns the results as a DataTable object
Public Shared Function ExecuteSelectCommand(ByVal comm As DbCommand) As DataTable
' The DataTable to be returned
Dim table As DataTable
' Execute the command, making sure the connection gets closed in the
' end
Try
' Open the data connection
comm.Connection.Open()
' Execute the command and save the results in a DataTable
Dim reader As DbDataReader = comm.ExecuteReader
table = New DataTable
table.Load(reader)
' Close the reader
reader.Close()
Catch ex As Exception
Utilities.ErrorResult(ex)
Throw
Finally
' Close the connection
comm.Connection.Close()
End Try
Return table
End Function
' creates and prepares a new DbCommand object on a new connection
Public Shared Function CreateCommand() As DbCommand
' Obtain the database provider name
Dim dataProviderName As String = SIOnlineMusicShopConfiguration.DbProviderName
' Obtain the database connection string
Dim connectionString As String = SIOnlineMusicShopConfiguration.dbConnectionString
' Create a new data provider factory
Dim factory As DbProviderFactory = DbProviderFactories.GetFactory(dataProviderName)
' Obtain a database-specific connection object
Dim conn As DbConnection = factory.CreateConnection
' Set the connection string
conn.ConnectionString = connectionString
' Create a database-specific command object
Dim comm As DbCommand = conn.CreateCommand
' Set the command type to stored procedure
comm.CommandType = CommandType.StoredProcedure
' Return the initialized command object
Return comm
End Function
End Class
Any help would be greatly appreciated.
Thanks in advance
-=Stylus=--