I can't seem to locate any easy way to create dynamic class properties.
Essentially, I want to take the column headers from a data result set,
create a property having the column header name, and then set the value
of the property to the data in the corresponding field.
For example, if I had this row from table "users":
ID Name Age
1 Barry 35
2 Brenda 33
....I could then write a SQL statement, e.g., "SELECT * from users where
ID = 2"
....and then pass it through a class
Users myuser = new Users();
that would loop through the column names, creating the properties Name
and Age (right there!) and then setting the property value by looping
through the values. Accessing the "Users" class would yield...
Users.Name = Brenda
Users.Age = 33
What I'm trying to avoid is typing out 100 column header names, and then
having to add or subtract more names as the database changes...also, I
could create classes out of any-ol'-table much easier.
I'd sure appreciate some help!
--Brent 1 2644
You could in .NET but it would be way too slow at runtime.
Check out the source code for the object mapper below.
It creates the classes for you at design time. A much faster
approach.
--
Robbe Morris - 2004/2005 Microsoft MVP C#
Free Source Code for ADO.NET Object Mapper To DataBase Tables And Stored
Procedures http://www.eggheadcafe.com/articles/..._generator.asp
"Brent" <"writeBrent at the google mail place"> wrote in message
news:11******** *****@corp.supe rnews.com... I can't seem to locate any easy way to create dynamic class properties. Essentially, I want to take the column headers from a data result set, create a property having the column header name, and then set the value of the property to the data in the corresponding field.
For example, if I had this row from table "users": ID Name Age
1 Barry 35 2 Brenda 33
...I could then write a SQL statement, e.g., "SELECT * from users where ID = 2"
...and then pass it through a class
Users myuser = new Users();
that would loop through the column names, creating the properties Name and Age (right there!) and then setting the property value by looping through the values. Accessing the "Users" class would yield...
Users.Name = Brenda Users.Age = 33
What I'm trying to avoid is typing out 100 column header names, and then having to add or subtract more names as the database changes...also, I could create classes out of any-ol'-table much easier.
I'd sure appreciate some help!
--Brent This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Rob |
last post by:
Dear All,
I have a class that exposes a few properties. These properties are used in a
DataGridView. The code for that is shown bellow. The problem is that I also
need to show data/columns/properties in the DataGridView that are not known
at compile time. The total number of these data/columns/properties is also
not known. So the question is how can I dynamically add properties (indexers
don't seem to work) so that DataGridView can show...
|
by: Nathan Bloomfield |
last post by:
Does anyone know if there is any documentation which relates to Access2k + ?
or can anyone help adjust the code?
I am having trouble converting the DAO references.
TITLE :INF: How to Create a Dynamic Crosstab Report
PRODUCT :Microsoft Access
PROD/VER:1.00 1.10
OPER/SYS:WINDOWS
|
by: J.B |
last post by:
I have a datagrid that will display different datasets, (it runs
different sprocs based on a value in the querystring) but it will
always return 6 columns. The 5th and 6th columns are always Date and
Currency format, all others are strings.
I'd like to build one datagrid to handle this datagrid dynamically. I
have it working now, all except the formatting of the 5th (Date) and
6th (Currency) columns.
Since the headers for those...
|
by: Joel Reinford |
last post by:
I would like to build a class that has properties which can be accessed by
string names or index numbers in the form of MyClass.Item("LastName"). The
string names or item index values would be populated by a data-driven loop.
I need a few pointers to get me started in the right direction. I'm pretty
sure that I need a default Item property but I'm not sure how to create that
or index the other properties. A short code example is below
...
|
by: Lloyd Sheen |
last post by:
Is there an example of VB code which will take a datasource and extract from
that the needed info (columns etc.) to create the columns and then bind the
data?
This seems so much more difficult to do an ad-hoc query.
Lloyd Sheen
| |
by: Bongard |
last post by:
I have a dynamic range that I would like to use as a linked table into
Access. The problem is that Access doesn't seem to want to to
recognize the dynamic range when you click on "show named ranges" in
the Link Spreadsheet wizard. The reason I want to use a dynamic range
is because when the data in my excel spreadsheet changes the linked
table will import blank rows that were previously used from the bottom
of the spreadsheet. I can't...
|
by: John Wright |
last post by:
I have a class that I populate properties from a table in my database. I
create the properties in my class one for one with the columns in the tables
that I use to fill the class. Some properties are not loaded until a
function is called to load the properties when needed. In this class I have
about 50 properties that I expose to the client. The client, in turn, can
update most of the properties with new data, then call the update...
|
by: DaveL |
last post by:
Hello
I want to build Dynamic Paramers for a Sql Insert
below is what i have so far but...determinthe column type and length im
having Problems with
Tks
dave
string sInsert = "Insert into oaDental..dentalClaims (";
|
by: JamesOo |
last post by:
I have the code below, but I need to make it searchable in query table,
below code only allowed seach the table which in show mdb only. (i.e. have 3 table, but only can search either one only, cannot serch by combine 3 table)
Example I have the query table below, how do I make the code to seach based on the query from this:
SELECT Product.ID, Product.Description, Quantity.Quantity, Quantity.SeialNo, Quantity.SupplierID,...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |