Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Generic code for updating business object from dataset - feedback requested

Generic code for updating business object from dataset - feedback requested

Scheduled Pinned Locked Moved Visual Basic
databasecsharpbusinessbeta-testing
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lee Ludden
    wrote on last edited by
    #1

    I have a project where I am converting a very complex MS Access front end to a VB.Net application. There are close to a hundred tables in a SQL database containing mostly but not completely static data that I plan on turning into individual classes. So for each class I have a strongly typed dataset for per table, and a class. Each table has an ID (IDENTITY) field as a unique key. What I am wanting to do is have a generic way of populating and updating each of these classes. Here is what I have so far. First I created a new Attribute class

    Then in my class I use this to flag each property with the field that is associated with it in the database (the database is close to 10 years old and has no naming conventions whatsoever).

    Imports System.Reflection

    Public Class TransportMethod
    Implements IEquatable(Of TransportMethod)
    Private _code As String
    Private _iD As Integer
    Private _description As String
    Private _requiresAttendant As Boolean

    Public Sub New(ByVal row As dsTransportMethod.dtTransportMethodsRow)
        ProcessRow(row)
    End Sub
    
    <DataTableSource("TransportMethod")> \_
    Public Property Code() As String
        Get
            Return \_code
        End Get
        Protected Set(ByVal value As String)
            \_code = value
        End Set
    End Property
    
    <DataTableSource("TransportMethodDesc")> \_
    Public Property Description() As String
        Get
            Return \_description
        End Get
        Protected Set(ByVal value As String)
            \_description = value
        End Set
    End Property
    
    <DataTableSource("TransportMethodID")> \_
    Public Property ID() As Integer
        Get
            Return \_iD
        End Get
        Protected Set(ByVal value As Integer)
            \_iD = value
        End Set
    End Property
    
    <DataTableSource("RequiresAttendant")> \_
    Public Property RequiresAttendant() As Boolean
    
    D 1 Reply Last reply
    0
    • L Lee Ludden

      I have a project where I am converting a very complex MS Access front end to a VB.Net application. There are close to a hundred tables in a SQL database containing mostly but not completely static data that I plan on turning into individual classes. So for each class I have a strongly typed dataset for per table, and a class. Each table has an ID (IDENTITY) field as a unique key. What I am wanting to do is have a generic way of populating and updating each of these classes. Here is what I have so far. First I created a new Attribute class

      Then in my class I use this to flag each property with the field that is associated with it in the database (the database is close to 10 years old and has no naming conventions whatsoever).

      Imports System.Reflection

      Public Class TransportMethod
      Implements IEquatable(Of TransportMethod)
      Private _code As String
      Private _iD As Integer
      Private _description As String
      Private _requiresAttendant As Boolean

      Public Sub New(ByVal row As dsTransportMethod.dtTransportMethodsRow)
          ProcessRow(row)
      End Sub
      
      <DataTableSource("TransportMethod")> \_
      Public Property Code() As String
          Get
              Return \_code
          End Get
          Protected Set(ByVal value As String)
              \_code = value
          End Set
      End Property
      
      <DataTableSource("TransportMethodDesc")> \_
      Public Property Description() As String
          Get
              Return \_description
          End Get
          Protected Set(ByVal value As String)
              \_description = value
          End Set
      End Property
      
      <DataTableSource("TransportMethodID")> \_
      Public Property ID() As Integer
          Get
              Return \_iD
          End Get
          Protected Set(ByVal value As Integer)
              \_iD = value
          End Set
      End Property
      
      <DataTableSource("RequiresAttendant")> \_
      Public Property RequiresAttendant() As Boolean
      
      D Offline
      D Offline
      David Mujica
      wrote on last edited by
      #2

      If you are going to take the time to build new classes for each of your tables, then why are you trying to come up with a generic way of accessing the data ? You are willing to commit the time to create classes, so why don't you take advantage of .NET and write each class specifically for each table ? In the long run, won't you be better off ? Research the topics of DAL (data access layer) and you will get a better idea of how to build an interface to your data. This article has some really good points ... Building an N-Tier Application in VB.NET, in 8 Steps[^] Don't make things harder than they really are :cool: Good luck. :thumbsup:

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups