|
Ryan Blake wrote: TheCodeProject has really helped me progress quickly and get up to scratch quickly
by offering top quality post that are direct and easy to follow.
So why don't you search codeproject?
These links will help you:
irregularshapedform[^]
ShapeControldotNET[^]
|
|
|
|
|
Hi.
I have some enums generated from xsd files, which I'll use intensively in my program.
One task involves storing data into a database, including these enum values. The field type of the database which is use for this table is text.
How should I store, and more importantly retrieve the values of the enums?
How could I convert from string to a custom enum type?
Thanks.
|
|
|
|
|
Hello,
As enum is int Type it makes no sence to store it as a text I guess!
I would cast it to (int)MyEnum.
But you should use fixed values for your enum, which is important for consistance after updates!
All the best,
Martin
|
|
|
|
|
Ok, so for example if I have this enum(mind the syntax):
Dog - 1
Cat - 2
Flying Squirrel - 3
and I store in the database values 1,2 or 3, is it possible after I retrieve these values to convert 1 to Dog, 2 to Cat and 3 to Flying Squirrel?
Thanks.
|
|
|
|
|
Hello,
Just do the casting in the other direction.
int dbvalue = ?;
FancyAnimals dbFancyAnimals = (FancyAnimals)dbvalue;
All the best,
Martin
|
|
|
|
|
Sure, simply cast them to the enumeration and it will work!
enum Numbers
{
One = 1,
Two = 2,
Three = 3
}
class Program
{
static void Main(string[] args)
{
for (int i = 1; i <= 3; i++)
{
Numbers n = (Numbers) i;
Console.WriteLine(n.ToString());
}
}
}
Cheers,
Vıkram.
After all is said and done, much is said and little is done.
|
|
|
|
|
Martin# wrote: As enum is int Type it makes no sence to store it as a text I guess!
I think he's talking about the names of the enumeration values. For instance:
enum Numbers
{
One = 1,
Two = 2,
Three = 3
} He wants to store "One", "Two", and "Three" in the database and somehow use them to get 1, 2, and 3. I used something like this at my previous company, but I don't remember now.
Cheers,
Vıkram.
After all is said and done, much is said and little is done.
|
|
|
|
|
Right. I want to store "One", "Two", "Three" and retrieve whatever values are required to correctly fill the enum variables in my program.
Sorry for the confusion.
|
|
|
|
|
I think I understood it.
Look at my posts.
All the best,
Martin
|
|
|
|
|
Cheers,
Vıkram.
After all is said and done, much is said and little is done.
|
|
|
|
|
Vikram A Punathambekar wrote:
I wanted to say, that I understood it, but recomended an other solution!
All the best,
Martin
|
|
|
|
|
Hello.
Here is what you were searching for.
Again I don't recomend it!
string actstring ="Dog";
FancyAnimal actAnimal = (FancyAnimal)Enum.Parse(typeof(FancyAnimal), actstring, true);
Be aware that it will throw an exception if it has no member of that fits!
All the best,
Martin
|
|
|
|
|
Thanks.
A man's gotta' do what a man's gotta' do. Even if it's not recommendable.
|
|
|
|
|
blackjack2150 wrote: A man's gotta' do what a man's gotta' do. Even if it's not recommendable.
But safety first, my friend.
You could validate the string, if you get all the members of the Enum and store it:
string[] members = Enum.GetNames(typof(FancyAnimal));
System.Collections.Specialized.StringCollection memberscollection = new System.Collections.Specialized.StringCollection();
memberscollection.AddRange(members);
Than just make the check:
string act ="dog";
if(memberscollection.Contains(act))
{
Hope it helps!
All the best,
Martin
|
|
|
|
|
Schweet.
Why do you not recommend it? Because of the exception it could throw, or because it's slow?
Cheers,
Vıkram.
After all is said and done, much is said and little is done.
|
|
|
|
|
Vikram A Punathambekar wrote: Why do you not recommend it? Because of the exception it could throw, or because it's slow?
No, just imagen that.
Software 1:
public enum FancyAnimal
{
dog= 0,
cat= 1,
squirel= 2,
}
text "squirel" is stored in db.
Than in Software 2:
public enum FancyAnimal
{
dog= 0,
cat= 1,
squirrel= 2,
}
No good!
All the best,
Martin
|
|
|
|
|
I assume you're trying to highlight the misspelling of Squirrel?
If the apps are unrelated, it doesn't make sense to make them share the same DB table for storage. Personally, I would go for a readable representation like Dog rather than 0 in the database.
I like your suggestion for a different reason - the code is simpler. I guess I could store the 0 along with Dog in the database and use that mapping.
Cheers,
Vıkram.
After all is said and done, much is said and little is done.
|
|
|
|
|
Hello,
Vikram A Punathambekar wrote: I assume you're trying to highlight the misspelling of Squirrel?
Exactelly!
Vikram A Punathambekar wrote: If the apps are unrelated, it doesn't make sense to make them share the same DB table for storage.
Sorry, for my bad example!
I off course ment:
YourProgramm Version 1:
and
YourProgramm Version 2:
Vikram A Punathambekar wrote: Personally, I would go for a readable representation like Dog rather than 0 in the database.
As a customer, I would be pretty pissed if I had to fill in my formulars again after a software update!
Only because there was a missspelling found in the code!
All the best,
Martin
|
|
|
|
|
Hi All,How can I create TreeView Control in WebForm.Im using ASP.Net1.1v.
Help me,please.Thank You in advance..
Hi,Im Razana
|
|
|
|
|
Hi Razana,
You can use the Internet Explorer Webcontrols of Microsoft for this. They add 3 more controls for you to use in ASP.Net 1.1 (I have blogged about the tabcontrol[^]).
You can download them Here[^].
Cu
Sven Cipido
|
|
|
|
|
can i save a graphich(ex rectangle) with DrawRectangle(bla...bla...) into some variabel ??
thx
Beginner C#
Yogyakarta - Indonesia
|
|
|
|
|
i think u can store the objects in form of binary file
rahul
|
|
|
|
|
i want a windowsservice which generates crystalreport in pdf automatically at regular duarations and mail has to send ..ex: i want to generate report automatically at 30 or 31st of everymonth and after generation it has to send mail itself automatically.can u please anybody help me out
rajesh m
|
|
|
|
|
thanks to all who help...
1)How do i read a 2 byte, 4 byte, or 8 byte value? I know how to read a one byte, but that only goes up to 255...
2)If any of you are familiar assembly, i need know now how to change (write) to an addresses hex dump, also known as Array of Byte (in most memory editing engines).
3) Reading/writing to a pointer I.E (0x1009624, offset: 0xb14), or any other pointer...
thanks in advanced
|
|
|
|
|