473,473 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

most seamless way to store a C# enum value in a SQL Server database?

One of the most convenient features of Visual Studio .Net and ASP.Net
is being able to add rows to a SQL Server database in an
intellisense-safe way, with code like:

newRow.Setparent_post_idNull();
newRow.post_text = this.lblMessageBody.Text;
newRow.post_datetime = System.DateTime.Now;

dsLocalDataSet1.user_post.Adduser_postRow(newRow);
this.oleDbUserPostAdapter.Update(dsLocalDataSet1.u ser_post);

If I want my "row" objects to contain an enumerated type and to still
be stored in the SQL Server database table, is there a seamless way to
do that without sacrificing all the benefits of typed datasets and the
code they automatically generate as in the examples above?

If I can't do it with true enums (called, for example,
PostStatus.AwaitingResponse and PostStatus.HasBeenRepliedTo), then I
could have a PostStatus class with public static constant strings
PostStatus.AwaitingResponse, whose value is "AwaitingResponse", and
PostStatus.HasBeenRepliedTo, whose value is "HasBeenRepliedTo", and
then have the type of that data field simply be a string when stored
to the database, and then when reading from the database, compare the
string value to PostStatus.AwaitingResponse or to
PostStatus.HasBeenRepliedTo to see what it is. (Storing them as ints
would make sorting and other operations faster, but storing them as
strings would make it easier to see what the actual values are when
viewing the database table directly.) Just wondering what the pros
usually do in this case!

-Bennett
Nov 18 '05 #1
1 2264
the best is to create a domain table with the int value and enum name, then
store the actual int value in your tables.

-- bruce (sqlwork.com)
"Bennett Haselton" <be*****@peacefire.org> wrote in message
news:e6**************************@posting.google.c om...
One of the most convenient features of Visual Studio .Net and ASP.Net
is being able to add rows to a SQL Server database in an
intellisense-safe way, with code like:

newRow.Setparent_post_idNull();
newRow.post_text = this.lblMessageBody.Text;
newRow.post_datetime = System.DateTime.Now;

dsLocalDataSet1.user_post.Adduser_postRow(newRow);
this.oleDbUserPostAdapter.Update(dsLocalDataSet1.u ser_post);

If I want my "row" objects to contain an enumerated type and to still
be stored in the SQL Server database table, is there a seamless way to
do that without sacrificing all the benefits of typed datasets and the
code they automatically generate as in the examples above?

If I can't do it with true enums (called, for example,
PostStatus.AwaitingResponse and PostStatus.HasBeenRepliedTo), then I
could have a PostStatus class with public static constant strings
PostStatus.AwaitingResponse, whose value is "AwaitingResponse", and
PostStatus.HasBeenRepliedTo, whose value is "HasBeenRepliedTo", and
then have the type of that data field simply be a string when stored
to the database, and then when reading from the database, compare the
string value to PostStatus.AwaitingResponse or to
PostStatus.HasBeenRepliedTo to see what it is. (Storing them as ints
would make sorting and other operations faster, but storing them as
strings would make it easier to see what the actual values are when
viewing the database table directly.) Just wondering what the pros
usually do in this case!

-Bennett

Nov 18 '05 #2

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

Similar topics

7
by: Charles Crume | last post by:
Hello all; I have used dBASE, and other computer languages/databases, for years. They all have a logical field type. However, the version of MySQL used by the ISP hosting my site does not...
11
by: hoopsho | last post by:
Hi Everyone, I am trying to write a program that does a few things very fast and with efficient use of memory... a) I need to parse a space-delimited file that is really large, upwards fo a...
6
by: giannik | last post by:
I have an Enum Structure Public Enum MyEnum EnumVal1=0 EnumVal2=1 EnumVal2=2 end enum I save in an access database this enum value as an integer (0=EnumVal1,
11
by: =?Utf-8?B?dG9iaXdhbl9rZW5vYmk=?= | last post by:
The following code is in a custom deserializer: object value = (int) 1; string nameToParse = Enum.GetName(field.FieldType, value); value = Enum.Parse(field.FieldType, nameToParse); Currently...
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
Oralloy
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.