Results 1 to 2 of 2

Thread: [2005] How to improve performance of a data/business logic classes?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2005
    Posts
    29

    [2005] How to improve performance of a data/business logic classes?

    Hi, I've created several classes that create a data layer and a seperate business layer for three different tables from a DB. I've combined two tables with one to one relationships in the class 'Loan' and have a separate class for a table that is one to many to those in class 'Loan' in a class called 'Brokers'. You all still with me? Now the way I have done it works, however I am having performance issues, mainly is that it eats up my cpu on a duel core computer. I'm looking for a better way to structure these classes to achieve what I want. I encourage you to be frank and shoot down any and all mistakes...


    VB Code:
    1. Imports Microsoft.VisualBasic
    2. Imports System.Configuration.ConfigurationManager
    3. Imports System.Data.SqlClient
    4. Imports System.Data
    5. Imports System.Collections.Generic
    6. Public Class DataTracDB
    7.     Private Shared connectionstring As String
    8.  
    9.     Shared Sub New()
    10.         connectionstring = ConfigurationManager.ConnectionStrings("DMDConnectionString").ConnectionString
    11.     End Sub
    12.  
    13.     'returns a dataset full dataset with no parameters
    14.     Public Shared Function ExecuteDataSet(ByVal sql As String) As Data.DataSet
    15.         Dim ds As New Data.DataSet
    16.         Dim da As New SqlDataAdapter(sql, connectionstring)
    17.  
    18.         da.Fill(ds)
    19.         Return ds
    20.     End Function
    21.  
    22.     Public Shared Function testRow(ByVal column As String, ByVal row As DataRow) As String
    23.         If row(column) Is DBNull.Value Then
    24.             Return ""
    25.         Else
    26.             Return row(column)
    27.         End If
    28.     End Function
    29. End Class
    30. Public Class Broker
    31.     Inherits DataTracDB
    32.     Private strBranchID As String
    33.     Private strBrokerID As String
    34.  
    35.     Public Property brokerID() As String
    36.         Get
    37.             Return strBrokerID
    38.         End Get
    39.         Set(ByVal value As String)
    40.             strBrokerID = value
    41.         End Set
    42.     End Property
    43.  
    44.     Public Property branchID() As String
    45.         Get
    46.             Return strBranchID
    47.         End Get
    48.         Set(ByVal value As String)
    49.             strBranchID = value
    50.         End Set
    51.     End Property
    52.     Public Function SelectBroker() As List(Of Broker)
    53.  
    54.         Dim ds As DataSet = ExecuteDataSet("SELECT brokers_id, idnum, address, city, state, zip, phone_pre, phone, fax_pre, fax, whole_rep, president FROM brokers")
    55.         Dim arr As New List(Of Broker)
    56.  
    57.         For Each row As DataRow In ds.Tables(0).Rows
    58.             Dim c As New Broker
    59.  
    60.             c.brokerID = testRow("brokers_id", row)
    61.             c.branchID = testRow("idnum", row)
    62.             arr.Add(c)
    63.         Next
    64.         Return arr
    65.     End Function
    66. End Class
    67. Public Class Loan
    68.     Inherits Broker
    69.     Private strLoanID As String
    70.     Private strloanAmt As String
    71.     Private strLien As String
    72.     Private strBrokerID As String
    73.     Private strFundedDate As String
    74.  
    75.     Public Property LoanID() As String
    76.         Get
    77.             Return strLoanID
    78.         End Get
    79.         Set(ByVal value As String)
    80.             strLoanID = value
    81.         End Set
    82.     End Property
    83.  
    84.     Public Property LoanAmount() As String
    85.         Get
    86.             Return strloanAmt
    87.         End Get
    88.         Set(ByVal value As String)
    89.             strloanAmt = value
    90.         End Set
    91.     End Property
    92.  
    93.     Public Property lien() As String
    94.         Get
    95.             Return strLien
    96.         End Get
    97.         Set(ByVal value As String)
    98.             strLien = value
    99.         End Set
    100.     End Property
    101.  
    102.  
    103.     Public Property fundedDate() As String
    104.         Get
    105.             Return strFundedDate
    106.         End Get
    107.         Set(ByVal value As String)
    108.             strFundedDate = value
    109.         End Set
    110.     End Property
    111.  
    112.     Public Function SelectLoan() As List(Of Loan)
    113.  
    114.         Dim ds As DataSet = ExecuteDataSet("SELECT dbo.gen.file_id, dbo.gen.loan_num, dbo.gen.loan_amt, dbo.fun.funded, dbo.gen.lien, dbo.gen.brokers_id FROM dbo.gen INNER JOIN dbo.fun ON dbo.gen.file_id = dbo.fun.file_id")
    115.         Dim arr As New List(Of Loan)
    116.  
    117.         For Each row As DataRow In ds.Tables(0).Rows
    118.             Dim c As New Loan
    119.             Dim branchBroker As New Broker
    120.  
    121.             For Each broker As Broker In branchBroker.SelectBroker
    122.  
    123.                 If testRow("brokers_id", row) = broker.brokerID Then
    124.  
    125.                     c.LoanID = DataTracDB.testRow("file_id", row)
    126.                     c.lien = testRow("lien", row)
    127.                     c.LoanAmount = testRow("loan_amt", row)
    128.                     c.brokerID = broker.branchID
    129.                     c.fundedDate = testRow("funded", row)
    130.  
    131.                     arr.Add(c)
    132.                 End If
    133.             Next
    134.         Next
    135.         Return arr
    136.     End Function
    137.  
    138. End Class

  2. #2
    Fanatic Member Dnereb's Avatar
    Join Date
    Aug 2005
    Location
    Netherlands
    Posts
    863

    Re: [2005] How to improve performance of a data/business logic classes?

    First of all tak a look at all the objects you are using in your app.
    And narrow the standard imports down as musc as possible.

    Try to narrow the list array down to what you really neeed
    Dim arr As New List(Of Loan)
    maybe
    Dim arr() as Loan

    I probablymissed it but maybe you could loose thes imports:
    Imports Microsoft.VisualBasic
    Imports System.Configuration.ConfigurationManager
    why can't programmers keep and 31 Oct and 25 dec apart. Why Rating is Useful
    for every question you ask provide an answer on another thread.

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