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. C#
  4. Explanation about Properties

Explanation about Properties

Scheduled Pinned Locked Moved C#
databasequestion
4 Posts 3 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.
  • R Offline
    R Offline
    Rostrox
    wrote on last edited by
    #1

    Hello: Is there any web site where I can find a very good explanation about the use of properties and mainly the justification of this in Database fields or (web)Forms fields ? Many thanks!!!

    H P 2 Replies Last reply
    0
    • R Rostrox

      Hello: Is there any web site where I can find a very good explanation about the use of properties and mainly the justification of this in Database fields or (web)Forms fields ? Many thanks!!!

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      You mean class properties? I don't see how this relates to databases or web form fields. If you are talking about creating business objects that map logical business data models (not a one-for-one mapping to a database, which is a poor design), then it's because it abstracts the actual data model away, leaving your code with an abstract way of declaring and using the relationships between your business objects. You can then implement a data tier which uses this information and updates the database. With an abstract design, you could always use a different data tier implementation to talk with different databases or even different data sources (like XML files). If you mean class properties, this comes down to common object-oriented programming. The ubiquitous example is the Person and Company classes. Properties of these classes define the name of a person or company and other data associated with an instance of the class. You define methods when you actually want to perform an operation on that class. If you're new to object-oriented development, I suggest you pick up a good book from www.amazon.com[^], or try a google search on object-oriented development[^]. The concept of properties and methods is common to all true object-oriented languages, like all the ".NET Languages" (those targeting the common language runtime, or CLR) and Java.

      Microsoft MVP, Visual C# My Articles

      1 Reply Last reply
      0
      • R Rostrox

        Hello: Is there any web site where I can find a very good explanation about the use of properties and mainly the justification of this in Database fields or (web)Forms fields ? Many thanks!!!

        P Offline
        P Offline
        pgraeve
        wrote on last edited by
        #3

        It is difficult to tell exactly what you are asking here - but if you talking about directly mapping database fields to a text box (or similiar control) on a form (of course, as the other message said, this is not a recommended OO methodology) but I'll use it sometimes for test purposes etc. If you are using Sql server you can use the following query to simply query the field metadata from Sql's System Tables. You can then loop through this recordset and assign the fields to the corresponding Form controls. If you are consistent with your naming conventions (i.e., naming the controls the same name as the fields) you can do this in one simple loop. In addition, you can setup your Update procedure and Insert procedure parameters in the same loop. As mentioned before, I wouldn't do this for a production App - but works great to model try some test cases or work up a quick "demo" etc... Here is query to extract field meta data, this will work for a Table or a View since Sql stores the Columns Definitions for both in the same system tables. If you are using a Sproc for your select, the query is a little more complext but I can send that to you as well if you need it. Hope that helps... ALTER PROCEDURE dbo.GetFields ( @TableName varchar(128) ) AS SELECT o.sysObjectID, o.sysTableName, c.name AS sysFieldName, c.xtype AS sysDataTypeID, t.name AS sysDataType, c.length AS sysFieldSize, c.colid AS sysOrdinalPosition, c.isoutparam AS sysIsOutputParameter, ISNULL(c.scale, 0) AS sysScale, c.prec AS sysPrecision FROM dbo.systables o INNER JOIN dbo.syscolumns c ON o.sysObjectID = c.id INNER JOIN dbo.systypes t ON c.xtype = t.xtype WHERE o.sysTableName = @TableName ORDER BY c.colid

        H 1 Reply Last reply
        0
        • P pgraeve

          It is difficult to tell exactly what you are asking here - but if you talking about directly mapping database fields to a text box (or similiar control) on a form (of course, as the other message said, this is not a recommended OO methodology) but I'll use it sometimes for test purposes etc. If you are using Sql server you can use the following query to simply query the field metadata from Sql's System Tables. You can then loop through this recordset and assign the fields to the corresponding Form controls. If you are consistent with your naming conventions (i.e., naming the controls the same name as the fields) you can do this in one simple loop. In addition, you can setup your Update procedure and Insert procedure parameters in the same loop. As mentioned before, I wouldn't do this for a production App - but works great to model try some test cases or work up a quick "demo" etc... Here is query to extract field meta data, this will work for a Table or a View since Sql stores the Columns Definitions for both in the same system tables. If you are using a Sproc for your select, the query is a little more complext but I can send that to you as well if you need it. Hope that helps... ALTER PROCEDURE dbo.GetFields ( @TableName varchar(128) ) AS SELECT o.sysObjectID, o.sysTableName, c.name AS sysFieldName, c.xtype AS sysDataTypeID, t.name AS sysDataType, c.length AS sysFieldSize, c.colid AS sysOrdinalPosition, c.isoutparam AS sysIsOutputParameter, ISNULL(c.scale, 0) AS sysScale, c.prec AS sysPrecision FROM dbo.systables o INNER JOIN dbo.syscolumns c ON o.sysObjectID = c.id INNER JOIN dbo.systypes t ON c.xtype = t.xtype WHERE o.sysTableName = @TableName ORDER BY c.colid

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          To add to this (for the original poster), a more common data-binding example is to bind against a DataSet, or a business object like I mentioned. Either one could be filled from a data source using the provider pattern so that the implementation is really independent from the data. This is a good OO design.

          Microsoft MVP, Visual C# My Articles

          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