Last post Jul 19, 2011 04:49 AM by crooksey
Jul 18, 2011 01:18 PM|crooksey|LINK
This is not my first visit to the forum but it is my first post, I've found many answers on here for other questions since I started writing asp.net sites earlier this year. I've had to get my head around loads of different issues and I'm hoping to return
the 'favour' by helping others on here too!
I've been scratching my head over this for ages this afternoon and I'd appreciate a 2nd opinion even if it's to point out the obvious that I have more than likely missed!
I have DAL and BLL setup on my site and I can successfully execute an 'add' function in the BLL using a web form to add a 'customer load' to a database table
provided that the table is empty. The problem arises with a subsequent call to the BLL function instead my error response is called. If I truncate the table and try again it works and then again subsequent calls do not update the table. Annoying,
yes... stupid error, more than likely!
I am using various declared values as part of the statement in theory to minimise the number of errors these values are straight from my SQL DB so I know that they exist and are aiming at exactly the right product etc.
I'm thinking the error is coming as part of the boolean return in the rowsAffected call?!
My thanks in advance
Call to BLL Function From Code Behind in Page:
Protected Sub btnOk_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOk.Click
' Prepare for DB Update
' Get update method from BLL
Dim customerLoadLogic As New CustomerLoadBLL
' Setup necessary Variables and gather information from form ready for update
Dim BookingReference As String = txtBookingReference.Text.ToString
Dim CustomerGuid As Guid = New Guid("7C8EBE6D-53CC-450A-BE05-00036BBB82F3")
Dim CustomerUserGuid As Guid = New Guid("ebe49d29-ac51-49e5-8c81-269431dfacc7")
Dim BookingDate As DateTime = Now()
Dim CarrierGuid As Guid = New Guid(ddlCarrier.SelectedValue)
Dim LoadTypeGuid As Guid = New Guid(ddlTrailerType.SelectedValue)
Dim Cartons As Integer = 1
Dim Pallets As Integer = Convert.ToInt32(txtTotalPallets.Text.ToString)
' Add Load Record to customer_load
customerLoadLogic.AddCustomerLoad(BookingReference, CustomerGuid, CustomerUserGuid, BookingDate, CarrierGuid, LoadTypeGuid, Cartons, Pallets)
Catch ex As Exception
' Error Message
Response.Write("Error uploading Customer Load.")
<System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, True)> _
Public Function AddCustomerLoad(ByVal BookingReference As String, _
ByVal CustomerGuid As Guid, _
ByVal CustomerUserGuid As Guid, _
ByVal BookingDate As DateTime, _
ByVal CarrierGuid As Guid, _
ByVal LoadTypeGuid As Nullable(Of Guid), _
ByVal Cartons As Nullable(Of Integer), _
ByVal Pallets As Nullable(Of Integer)) As Boolean
' Create a new Customer Load Row instance
Dim dtCustomerLoads As New WMS.customer_loadDataTable()
Dim drLoad As WMS.customer_loadRow = dtCustomerLoads.Newcustomer_loadRow()
' Setup variables to pass onto query
drLoad.clo_reference = BookingReference
drLoad.clo_cst_guid = CustomerGuid
drLoad.clo_cus_guid = CustomerUserGuid
drLoad.clo_date = BookingDate
drLoad.clo_crr_guid = CarrierGuid
If LoadTypeGuid Is Nothing Then drLoad.Setclo_ldt_guidNull() Else drLoad.clo_ldt_guid = LoadTypeGuid
If Cartons Is Nothing Then drLoad.Setclo_cartonsNull() Else drLoad.clo_cartons = Cartons
If Pallets Is Nothing Then drLoad.Setclo_palletsNull() Else drLoad.clo_pallets = Pallets
drLoad.clo_guid = Guid.NewGuid
' Add new customer load
Dim rowsAffected As Integer = Adapter.Update(dtCustomerLoads)
' Checks if 1 row has been inserted and if so, update is true
Return rowsAffected = 1
Jul 18, 2011 03:24 PM|rtpHarry|LINK
Off the top of my head I would guess that you have set your id column to be a primary key but forgotten to set it as an auto-increment identity column?
Jul 19, 2011 04:04 AM|crooksey|LINK
drLoad.clo_guid = Guid.NewGuid
in the BLL Function should provide a new guid which is the primary key for the DB... But that might be the error, does Guid.NewGuid not provide a new uniqueidentifier?
Jul 19, 2011 04:49 AM|crooksey|LINK
After trying SQL statements direct into SQL Server looks like there was an indexible key assigned alongside the primary key on a different column. My thanks, you pointed me in the right direction and it's all working now! Ta!