nevets2001uk
IS-IT--Management
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...
When I run the code using the following on my page...
... 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)
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)