Results 1 to 9 of 9

Thread: [2008] n Tier, Classes and Data Access

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Location
    Three Rivers, MI
    Posts
    354

    [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:
    1. Public Class Customer
    2.     Inherits BOBase
    3.     Private Const CN_CustomerCode As String = "CustomerCode"
    4.     Private Const CN_CompanyName As String = "CompanyName"
    5.  
    6.     Private _CustomerCode As String
    7.     Public Property CustomerCode() As String
    8.         Get
    9.             Return _CustomerCode
    10.         End Get
    11.         Private Set(ByVal value As String)
    12.             _CustomerCode = value
    13.         End Set
    14.     End Property
    15.     Private _CompanyName As String
    16.     Public Property CompanyName() As String
    17.         Get
    18.             Return _CompanyName
    19.         End Get
    20.         Set(ByVal value As String)
    21.             If _CompanyName <> value Then
    22.                 Dim propertyName As String = "CompanyName"
    23.                 Me.DataStateChanged(EntityStateEnum.Modified)
    24.                 _CompanyName = value
    25.             End If
    26.         End Set
    27.     End Property
    28.     Private Sub New()
    29.  
    30.     End Sub
    31.     Public Shared Function Create(ByVal custCode As String) As Customer
    32.         Dim cust As Customer
    33.         Dim dt As DataTable
    34.         dt = DAC.ExecuteDataTable("GetCustomerByCode_SP", _
    35.             DAC.parameter(CN_CustomerCode, custCode))
    36.  
    37.         cust = New Customer()
    38.         With dt.Rows(0)
    39.             cust.CustomerCode = .Item(CN_CustomerCode).ToString
    40.             cust.CompanyName = .Item(CN_CompanyName).ToString
    41.         End With
    42.         cust.DataStateChanged(EntityStateEnum.Unchanged)
    43.         Return cust
    44.     End Function
    45. 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?

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Location
    Three Rivers, MI
    Posts
    354

    Re: [2008] n Tier, Classes and Data Access

    Any ideas?

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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?

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Location
    Three Rivers, MI
    Posts
    354

    Re: [2008] n Tier, Classes and Data Access

    I have bound it like this.



    Where do I set the Datamember properties?

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Location
    Three Rivers, MI
    Posts
    354

    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.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Location
    Three Rivers, MI
    Posts
    354

    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

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Location
    Three Rivers, MI
    Posts
    354

    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.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Location
    Three Rivers, MI
    Posts
    354

    Re: [2008] n Tier, Classes and Data Access

    This is what I have so far.
    VB Code:
    1. Public Function ProcessSave() _
    2.         As Boolean Implements MDIInterface.ProcessSave
    3.  
    4.         Dim success As Boolean
    5.         Dim aCust As Customer = Nothing
    6.         Try
    7.             aCust.ContactName = txtContact.Text
    8.             aCust.Notes = txtNotes.Text
    9.             aCust.Save()
    10.             Return success
    11.         Catch ex As Exception
    12.             MessageBox.Show(ex.Message & vbNewLine & ex.StackTrace)
    13.         End Try
    14.  
    15.     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.

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Location
    Three Rivers, MI
    Posts
    354

    Re: [2008] n Tier, Classes and Data Access

    Any ideas?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width