Hi,
I have a table with the data like this,
ID Status Description
1 R Read
2 U UnRead
D D Deleted
I want to load this data in a class (say named Status) which I want to use
through out my project and should be able to access it like,
Status.Read or
Status.UnRead or
Status.Deleted
with each returning their corresponding values as in the database table
shown above.
To sum it up I want to create an enum with values loaded from database. I
think it may be possible using Reflection or Custom Attributes but don't know
how to do it.
One more thing is if I use reflection than I guess I won't be able to use
Status.Read in design time which means no use of it, correct me if I am wrong.
Any ideas how to go about it?
Regards,
Waqas Pitafi 7 1141
Try using ObjectSpaces due in Whidbey and ADO.NET 2.0 providing object to
database mapping which is what i beleive you are looking for.
HTH
rawCoder
"Waqas Pitafi" <Wa*********@discussions.microsoft.com> wrote in message
news:76**********************************@microsof t.com... Hi,
I have a table with the data like this,
ID Status Description 1 R Read 2 U UnRead D D Deleted
I want to load this data in a class (say named Status) which I want to use through out my project and should be able to access it like,
Status.Read or Status.UnRead or Status.Deleted
with each returning their corresponding values as in the database table shown above.
To sum it up I want to create an enum with values loaded from database. I think it may be possible using Reflection or Custom Attributes but don't
know how to do it.
One more thing is if I use reflection than I guess I won't be able to use Status.Read in design time which means no use of it, correct me if I am
wrong. Any ideas how to go about it?
Regards, Waqas Pitafi
I am sorry but I need the solution using .NET 1.1.
"rawCoder" wrote: Try using ObjectSpaces due in Whidbey and ADO.NET 2.0 providing object to database mapping which is what i beleive you are looking for.
HTH rawCoder
"Waqas Pitafi" <Wa*********@discussions.microsoft.com> wrote in message news:76**********************************@microsof t.com... Hi,
I have a table with the data like this,
ID Status Description 1 R Read 2 U UnRead D D Deleted
I want to load this data in a class (say named Status) which I want to use through out my project and should be able to access it like,
Status.Read or Status.UnRead or Status.Deleted
with each returning their corresponding values as in the database table shown above.
To sum it up I want to create an enum with values loaded from database. I think it may be possible using Reflection or Custom Attributes but don't know how to do it.
One more thing is if I use reflection than I guess I won't be able to use Status.Read in design time which means no use of it, correct me if I am wrong. Any ideas how to go about it?
Regards, Waqas Pitafi
Waqas,
You say you want to use this enum throughout your project however for what.
What is not Unread, what is Deleted, what is Read.
After that it is maybe to tell how you can do that.
Cor ID Status Description 1 R Read 2 U UnRead D D Deleted
I want to load this data in a class (say named Status) which I want to use through out my project and should be able to access it like,
Status.Read or Status.UnRead or Status.Deleted
with each returning their corresponding values as in the database table shown above.
To sum it up I want to create an enum with values loaded from database. I think it may be possible using Reflection or Custom Attributes but don't
know how to do it.
One more thing is if I use reflection than I guess I won't be able to use Status.Read in design time which means no use of it, correct me if I am
wrong. Any ideas how to go about it?
Regards, Waqas Pitafi
Waqas,
The answer is simple and again starting with a question, why do you have
that status in so many places as I understand while it is always the same.
Just set it in one place and use it.
In a module or in a property from a shared class.
When you do not know how to do the last, reply.
I hope this helps?
Cor
I guess I am not able to explain it properly. I will try it again,
see,
Generally speaking these Status values should be fixed then I can hardcode
them in my code but that's not the case. If a new Status is included in the
system, I have to add necessary code for that.
Now why do I have to change the code? See the following code sample.
// New questions
DataListBind(ref dlNew, new
QuestionsSystem(UserName).CategorySummary(Question sStatus.Unread));
// Waiting For Answer
DataListBind(ref dlRead, new
QuestionsSystem(UserName).CategorySummary(Question sStatus.Read));
// Archive
DataListBind(ref dlArchive, new
QuestionsSystem(UserName).CategorySummary(Question sStatus.Answered));
While this is my QuestionsStatus enum
public enum QuestionsStatus
{
Ignore = -1,
Unread = 1,
Read = 2,
ForwardedToConsultant = 3,
ForwardedToMe = 4,
Answered = 5,
MarkedForDeletion = 6
}
which I have created as a duplicate for my table data.
Now say we add a new Status in the table called 'NeverDeleteMe', I have to
return to this enum and add the new Status and recompile my code.
Hope now you get my problem.
You could store the status values in a XML config file and then write a
routine to update the XML file whenever a new status value is added.
Hope this helps.
"Waqas Pitafi" <Wa*********@discussions.microsoft.com> wrote in message
news:28**********************************@microsof t.com... I guess I am not able to explain it properly. I will try it again,
see,
Generally speaking these Status values should be fixed then I can hardcode them in my code but that's not the case. If a new Status is included in
the system, I have to add necessary code for that.
Now why do I have to change the code? See the following code sample.
// New questions DataListBind(ref dlNew, new QuestionsSystem(UserName).CategorySummary(Question sStatus.Unread));
// Waiting For Answer DataListBind(ref dlRead, new QuestionsSystem(UserName).CategorySummary(Question sStatus.Read));
// Archive DataListBind(ref dlArchive, new QuestionsSystem(UserName).CategorySummary(Question sStatus.Answered));
While this is my QuestionsStatus enum public enum QuestionsStatus { Ignore = -1, Unread = 1, Read = 2, ForwardedToConsultant = 3, ForwardedToMe = 4, Answered = 5, MarkedForDeletion = 6 }
which I have created as a duplicate for my table data.
Now say we add a new Status in the table called 'NeverDeleteMe', I have to return to this enum and add the new Status and recompile my code.
Hope now you get my problem.
Waqas,
You show exactly what I tried to say in my previous question. And I try to
show you, that you are probably making it yourself very difficult.
QuestionStatuscurrent = 1
Or when you want to use the enum in that case
QuestionStatuscurrent = QuestionStatus.read // New questions DataListBind(ref dlNew, new QuestionsSystem(UserName).CategorySummary(Question sStatuscurrent));
// Waiting For Answer DataListBind(ref dlRead, new QuestionsSystem(UserName).CategorySummary(Question sStatuscurent));
// Archive DataListBind(ref dlArchive, new QuestionsSystem(UserName).CategorySummary(Question sStatuscurrent));
And when you have this in more programs, make a shared variable from
QuestionStatusCurrent either using a module or nice with a shared class and
a property.
Cor
.. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Waqas Pitafi |
last post by:
Hi,
I have a table with the data like this,
ID Status Description
1 R Read
2 U UnRead
D D ...
|
by: Jeff Patrick |
last post by:
I have a series of class libraries. Some of the functions require string
constants to be passed in in order to effect certain behavior. Over time the
list of strings that could be passed in grew...
|
by: keith bannister via .NET 247 |
last post by:
(Type your message here)
--------------------------------
From: keith bannister
Hi,
I'm new to .net (as of last week) but here goes.
I want to serialize/deserialize a file the conforms...
|
by: Keith Bannister |
last post by:
I'm new to .net so here goes.
I'm tying to deserialize a class that is associated with an XML
schema.
I created the C# class with xsd.exe as below:
xsd.exe /c /n:somenamespace...
|
by: newbie |
last post by:
Hello,
I am using a propertygrid to allow users to edit\create objects at
runtime, that can update records in a database. There are certain
properties (fields) that I wish to display as...
|
by: David Batt |
last post by:
Hello
I have a problem whereby I wish to setup a custom tooltip. I have the code attached to do this, it all works very wel
if you have the following code in a button click event on the form
...
|
by: CPD |
last post by:
From PHP, doing a DROP TABLE and a CREATE TABLE is successful, but doing a
LOAD FILE keeps failing, with the error "Access denied for user
'db_user'@'localhost' (using password: YES)". The...
|
by: Ryan Liu |
last post by:
Is that a good idea to add a Hashtable to System.Windows.Forms.Application
class? And we can put any user global data in it.
I have some class library used by a few other applications in slight...
|
by: Michael Bray |
last post by:
With the recent release of EF I've decided to dig into it a bit more than I
did before... the question I'm specifically interested in, but haven't
been able to find a resource to answer it is......
|
by: Queez |
last post by:
Very quick question.
I have a master page (M1) and three content pages (C1, C2, C3). In M1, there's a list of three anchors (A1, A2, A3) which point towards the three content pages.
The...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| |