Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Developing a Business Logic Layer

Status
Not open for further replies.

nevets2001uk

IS-IT--Management
Joined
Jun 26, 2002
Messages
609
Location
GB
I have created a DAL (.xsd) on a new site I am developing and have succesfully been able to use it to read and write data to my database.

Trying to take this further I am working on a BLL class to handle the data entry. I have been following the 'Working with Data in ASP.NET 2.0 : Creating a
Business Logic Layer' tutorial from ASP.NET and come up with the following code...

Code:
Imports SJGTableAdapters

Public Class PendingGuestbookBLL

    Private _GuestbookPendingAdapter As GUESTBOOK_PENDINGTableAdapter = Nothing
    Protected ReadOnly Property Adapter() As GUESTBOOK_PENDINGTableAdapter
        Get
            If _GuestbookPendingAdapter Is Nothing Then
                _GuestbookPendingAdapter = New GUESTBOOK_PENDINGTableAdapter
            End If
        End Get
    End Property

    'ADD A NEW PENDING GUESTBOOK ENTRY
    Public Function AddGuestbookPending(ByVal ClientName As String, ByVal Email As String, ByVal Location As String, ByVal Message As String, ByVal IPAddress As String, ByVal DateTime As Date)
        Dim PendingGuestbook As New SJG.GUESTBOOK_PENDINGDataTable
        Dim PendingEntry As SJG.GUESTBOOK_PENDINGRow = PendingGuestbook.NewGUESTBOOK_PENDINGRow

        'SET VALUES FOR THE NEW RECORD

        '## CLIENT NAME ##
        PendingEntry.NAME = ClientName
        '## EMAIL ##
        If Not Email Is Nothing Then : PendingEntry.EMAIL = Email
        Else : PendingEntry.SetEMAILNull()
        End If
        '## LOCATION ##
        If Not Location Is Nothing Then : PendingEntry.LOCATION = Location
        Else : PendingEntry.SetLOCATIONNull()
        End If
        '## MESSAGE ##
        PendingEntry.MESSAGE = Message
        '## IP ADDRESS
        PendingEntry.IPADDRESS = IPAddress
        '## DATE TIME ##
        PendingEntry.DATETIME = DateTime

        'ADD THE NEW ROW
        PendingGuestbook.AddGUESTBOOK_PENDINGRow(PendingEntry)
        Dim RowsAffected As Integer = Adapter.Update(PendingGuestbook)

        Return RowsAffected = 1
    End Function

End Class

When I run the code using the following on my page...

Code:
Dim PendingGuestbookLogic As New PendingGuestbookBLL()
        PendingGuestbookLogic.AddGuestbookPending(txtName.Text, txtEmail.Text, txtLocation.Text, txtMessage.Text, Request.ServerVariables("REMOTE_ADDR"), DateTime.Now)

... it comes up with the error that GUESTBOOK_ID does not accept nulls. However this is primary key field with identity enabled to generate its ID.

Can anyone suggest why this field is not updating itself and allowing to add this new record from my form?

Does the above code look right?

Cheers,

Steve G (MCP)
 
I'm still struggling with this at the moment.

I think there's a problem with the code as I tried a simple method to simply read the data using a TableAdapter that works normally and that failed as well with a different error.

I'm totally new to this layered approach to coding but want to try and figure it out as the concept makes good sense!

Cheers,



Steve G (MCP)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top