473,408 Members | 1,874 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Access class fields generically

Hi

I'm trying do create a generic base class for all of my data objects.
One of
the main requirements for this class is to be able to handle all
common db actions without need for implementing them in inherited
classes. To accomplish this I need a way to map values of class
fields to corresponding stored procedure parameters. The only way i
have figured out to do this would be to create a name-value struct
array and hold class fields in it.
My question is: is there a better way to do this? Is there a way to
get a field value by matching its name to a string (in this case it
would be a parameter name)?

Thanks
Nov 16 '05 #1
3 1356
why not use parameter collection object to store parameters. you can write a
wrapper to accept name/value and add that to paratemeter collection.

Av.

"Tomislav Bartolin" <ba***************@hotmail.com> wrote in message
news:26**************************@posting.google.c om...
Hi

I'm trying do create a generic base class for all of my data objects.
One of
the main requirements for this class is to be able to handle all
common db actions without need for implementing them in inherited
classes. To accomplish this I need a way to map values of class
fields to corresponding stored procedure parameters. The only way i
have figured out to do this would be to create a name-value struct
array and hold class fields in it.
My question is: is there a better way to do this? Is there a way to
get a field value by matching its name to a string (in this case it
would be a parameter name)?

Thanks

Nov 16 '05 #2
Tomislav Bartolin <ba***************@hotmail.com> wrote:
I'm trying do create a generic base class for all of my data objects.
One of
the main requirements for this class is to be able to handle all
common db actions without need for implementing them in inherited
classes. To accomplish this I need a way to map values of class
fields to corresponding stored procedure parameters. The only way i
have figured out to do this would be to create a name-value struct
array and hold class fields in it.
My question is: is there a better way to do this? Is there a way to
get a field value by matching its name to a string (in this case it
would be a parameter name)?


Sounds like a job for reflection - look up reflection in the MSDN
index, then "about reflection".

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
in addition to what Jon said, you might also want to look into using custom attributes to provide a level of flexibility. sounds like you are trying to build simple ORM framework

----- Jon Skeet [C# MVP] wrote: ----

Tomislav Bartolin <ba***************@hotmail.com> wrote
I'm trying do create a generic base class for all of my data objects
One o
the main requirements for this class is to be able to handle al
common db actions without need for implementing them in inherite
classes. To accomplish this I need a way to map values of clas
fields to corresponding stored procedure parameters. The only way
have figured out to do this would be to create a name-value struc
array and hold class fields in it
My question is: is there a better way to do this? Is there a way t
get a field value by matching its name to a string (in this case i
would be a parameter name)


Sounds like a job for reflection - look up reflection in the MSDN
index, then "about reflection"

--
Jon Skeet - <sk***@pobox.com
http://www.pobox.com/~skee
If replying to the group, please do not mail me to

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Masterblue | last post by:
Hi, Right know im teaching myself a little about CDONTS . But know I want to sent data form a database with a form. I wou ld like to do the following: - I have made a page with set of records....
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
4
by: u7djo | last post by:
Hi, I'm currently building an application in Access and as part of this need to import forms and modules from another database. Some of the imports will be revisions of existing forms/modules so I...
3
by: J E E | last post by:
Hi! Is it possible to access fields in a derived class using reflection? Code below works fine when I access it as a private member in the Page class, but not when accessing base class member...
7
by: sam.m.gardiner | last post by:
I'm working with VB.NET events and I want a way to disconnect all the handlers of an event. I want to do this in the object that is the source of the event. This is slightly tricky in VB.Net as the...
0
by: pedz | last post by:
I am trying to write a set of classes, probably template classes, to allow "pretty" and safe access to low level machine words. The syntax I would like to end up with is something like: foo =...
1
by: pontypete | last post by:
Hi all Ive managed to create an ASP & ACCESS local site/databse, Now the aim: Membership Number = 1 Fname = Peter ^ everything in the databse, I want to beable to have a search box within...
3
by: Mark Foley | last post by:
I am implementing some functionality where there is a single base class 'A' which provides some common functionality There are then two classes derived from 'A', call them 'B' and 'C'. Both 'B'...
4
by: BarryB | last post by:
I imported a large table of classes, teachers and students from Excel to MS Access. Up to a point, this worked out ok. Unfortunately, the students are represented as field names (Smith_Abigail,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.