0

I have this enum:

public enum SupportedISOCurrencySymbol { DKK = 208, EUR = 978, NOK = 578, SEK = 752 }

I save the value for an order in the approved_orders table, Currency field.

I populate the sql insert query with a parameter like:

cmd.Parameters.AddWithValue("?Currency",                        this.Currency);

Well, If i do debug on the above line I clearly see that this.Currency has value DKK.

Why then it inserts in the DB: 208?

Do you have any ideea?

Thanks.

0

3 Answers 3

3

SupportedISOCurrencySymbol is an enum, which has integer as base. "DKK" represents the number 208.

What you are seeing in the debug window, is the value of .ToString() on your enum, which is defined to return the name of the enum, not the value. If you want to send the string "DKK" to your database, you could simply state it explicitly:

cmd.Parameters.AddWithValue("?Currency", this.Currency.ToString());

Of course, the columns involved in the database would then need to be of a compatible text type.

Sign up to request clarification or add additional context in comments.

Comments

2

"DKK" is a friendly name for the value "208" for you (as programmer) to use in your code.

When the code is compiled all occurrences of "DKK" are replaced by "208" which will include the code that inserts the value into the database.

You could change your database schema to hold a string rather than an integer and store the name of the enum rather than it's value - but you would need to parse the string into an enum when reading it back out of the database into your code.

Comments

0

do you need to add a this.Currency.ToString()? so as to get the text not the numeric value of the enum?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.