|
-
Feb 15th, 2009, 06:27 PM
#1
Thread Starter
Hyperactive Member
[2008] n Tier, Classes and Data Access
I am working on my first n tier project and having a lot of trouble getting my head around wirining it all up. I have a customer class
VB Code:
Public Class Customer
Inherits BOBase
Private Const CN_CustomerCode As String = "CustomerCode"
Private Const CN_CompanyName As String = "CompanyName"
Private _CustomerCode As String
Public Property CustomerCode() As String
Get
Return _CustomerCode
End Get
Private Set(ByVal value As String)
_CustomerCode = value
End Set
End Property
Private _CompanyName As String
Public Property CompanyName() As String
Get
Return _CompanyName
End Get
Set(ByVal value As String)
If _CompanyName <> value Then
Dim propertyName As String = "CompanyName"
Me.DataStateChanged(EntityStateEnum.Modified)
_CompanyName = value
End If
End Set
End Property
Private Sub New()
End Sub
Public Shared Function Create(ByVal custCode As String) As Customer
Dim cust As Customer
Dim dt As DataTable
dt = DAC.ExecuteDataTable("GetCustomerByCode_SP", _
DAC.parameter(CN_CustomerCode, custCode))
cust = New Customer()
With dt.Rows(0)
cust.CustomerCode = .Item(CN_CustomerCode).ToString
cust.CompanyName = .Item(CN_CompanyName).ToString
End With
cust.DataStateChanged(EntityStateEnum.Unchanged)
Return cust
End Function
End Class
Just to test it out I put this is the Form Load Event
Dim myCode As String = "ABC"
Me.CustomerBindingSource1.DataSource = Customer.Create(myCode)
Nothing comes up. I don't get an error or anything. The form just loads with out anything in the fields (I have bound them all). When I set a Break Point on the Me.CustomerBindingSource it doesn't stop there either. Is there something that I am missing?
-
Feb 19th, 2009, 09:59 PM
#2
Thread Starter
Hyperactive Member
Re: [2008] n Tier, Classes and Data Access
-
Feb 20th, 2009, 02:40 AM
#3
Re: [2008] n Tier, Classes and Data Access
Your code looks alright, how have you bound the form fields? Have you set DataMember properties on the bound fields on the form?
-
Feb 20th, 2009, 08:50 PM
#4
Thread Starter
Hyperactive Member
Re: [2008] n Tier, Classes and Data Access
I have bound it like this.

Where do I set the Datamember properties?
-
Feb 20th, 2009, 09:11 PM
#5
Thread Starter
Hyperactive Member
Re: [2008] n Tier, Classes and Data Access
I found this here but there were no options to set.

The CustomerBinding has different names in these two screen shots but they are the same in the project.
Last edited by BukHix; Feb 20th, 2009 at 09:16 PM.
-
Feb 20th, 2009, 10:00 PM
#6
Thread Starter
Hyperactive Member
Re: [2008] n Tier, Classes and Data Access
I think I got it now. I had two issues. For some reason the form load event was not firing off when then form was loaded. Once I took care of that I started getting errors, which enabled me to track down the problem.
Next I removed the VS Designer Code for the control binding and did my own with this.
Dim aCust As Customer
aCust = Customer.Create("ABC")
txtCompany.Text = aCust.CompanyName
txtContact.Text = aCust.CustomerCode
-
Feb 21st, 2009, 05:16 PM
#7
Thread Starter
Hyperactive Member
Re: [2008] n Tier, Classes and Data Access
Ok the loading of the controls is working now. So the next thing I want to do is save any changes back to the database. Since I am not using the CustomerBindingSource I need to do it in code but I am unsure of the syntax.
Last edited by BukHix; Feb 22nd, 2009 at 06:52 PM.
-
Feb 22nd, 2009, 06:52 PM
#8
Thread Starter
Hyperactive Member
Re: [2008] n Tier, Classes and Data Access
This is what I have so far.
VB Code:
Public Function ProcessSave() _
As Boolean Implements MDIInterface.ProcessSave
Dim success As Boolean
Dim aCust As Customer = Nothing
Try
aCust.ContactName = txtContact.Text
aCust.Notes = txtNotes.Text
aCust.Save()
Return success
Catch ex As Exception
MessageBox.Show(ex.Message & vbNewLine & ex.StackTrace)
End Try
End Function
I get this error Object reference not set to an instance of an object.
at PTWin.frmCustomer.ProcessSave() When I try to do a save.
-
Feb 23rd, 2009, 02:24 PM
#9
Thread Starter
Hyperactive Member
Re: [2008] n Tier, Classes and Data Access
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|