473,657 Members | 2,389 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Return month from dropdown as integer

Hi,

I am new to C# so forgive my ignorance.

I need to write a month 'number' to a DB, ie January = 1, March=3 etc etc...

I have the month description in a combo box. I used an enum " enum
month{January = 1,February, March....... etc } " to load the combo.

I wanted to use the same to resolve the String retrieved form the combo into
the actual enum value.

How would I do this ??

I attempted to do an 'Array.binaryse arch' having populated an array with the
months of the year. That didnt work either.

Any help appreciated.

Jon.
Apr 26 '06 #1
2 6543
Bishman,

It depends how you populate the combobox.
Example
enum month{January = 1,February, March....... etc }

you can populate the combobox
combobox.Items. Add(month.Janua ry);
combobox.Items. Add(month.Febru ary);
etc.

you can do: (int)combobox.S electedItem;

If you populate the combobox with the names of the enumeration items you can
go for

(int)Enum.Parse (typeof(Months) , str)
--
HTH
Stoitcho Goutsev (100)

"Bishman" <jo************ *@btinternet.co m> wrote in message
news:OE******** ******@TK2MSFTN GP03.phx.gbl...
Hi,

I am new to C# so forgive my ignorance.

I need to write a month 'number' to a DB, ie January = 1, March=3 etc
etc...

I have the month description in a combo box. I used an enum " enum
month{January = 1,February, March....... etc } " to load the combo.

I wanted to use the same to resolve the String retrieved form the combo
into the actual enum value.

How would I do this ??

I attempted to do an 'Array.binaryse arch' having populated an array with
the months of the year. That didnt work either.

Any help appreciated.

Jon.

Apr 26 '06 #2
Hi Stoitcho,

Many thanks, the line " (int)Enum.Parse (typeof(Months) , str) " is the
one I wanted, works fine.

I had a play around with Enum.Parse today also but just couldnt get it to
play ball.

Many thanks, Much appreciated.

Bish.
"Stoitcho Goutsev (100)" <10*@100.com> wrote in message
news:uz******** ******@TK2MSFTN GP02.phx.gbl...
Bishman,

It depends how you populate the combobox.
Example
enum month{January = 1,February, March....... etc }

you can populate the combobox
combobox.Items. Add(month.Janua ry);
combobox.Items. Add(month.Febru ary);
etc.

you can do: (int)combobox.S electedItem;

If you populate the combobox with the names of the enumeration items you
can go for

(int)Enum.Parse (typeof(Months) , str)
--
HTH
Stoitcho Goutsev (100)

"Bishman" <jo************ *@btinternet.co m> wrote in message
news:OE******** ******@TK2MSFTN GP03.phx.gbl...
Hi,

I am new to C# so forgive my ignorance.

I need to write a month 'number' to a DB, ie January = 1, March=3 etc
etc...

I have the month description in a combo box. I used an enum " enum
month{January = 1,February, March....... etc } " to load the combo.

I wanted to use the same to resolve the String retrieved form the combo
into the actual enum value.

How would I do this ??

I attempted to do an 'Array.binaryse arch' having populated an array with
the months of the year. That didnt work either.

Any help appreciated.

Jon.


Apr 26 '06 #3

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

Similar topics

6
2997
by: Hasanain F. Esmail | last post by:
Hi all, I sincerly thank you all in advance for your help to solve this problem. I have been trying to find a solution to this problem for sometime now but have failed. I am working on a project that requires updating data every month. A typical examle is an apartment rental software but could be applied
6
2953
by: James Fortune | last post by:
Several U.S. holidays are defined as the Nth Xday of a given month. For example, Thanksgiving Day is on the 4th Thursday in November. I found the following functions useful in calculating the date of those holidays. Note: you can also use them to calculate the Last Monday in May (U.S. Memorial Day) by finding the 4th Monday in May and seeing if adding 7 keeps the value at or under 31. Example: Find day of Thanksgiving in 2007 ...
13
2155
by: Sara | last post by:
I have a query that pulls data for the month, using the Month End Date from a form (user enters) as criteria. It works. I want to use the same query to pull "month to date" data, on a weekly basis. So, for week 1, it would only show the first 7 days; week 2 the first 14 days, etc. If I enter the next month ending date (1/1/05) right now, I get the information for days since the last month end until current date. That's perfect. My...
8
9969
by: felecha | last post by:
Is there a control that I can put on a Form that would let a user select just the month value? I tried to find a way to make the DateTimePicker or the Month Calendar do what I want but I can't. I want a way for the user to say "Let me see what is in the database for the month of January 2004." I don't want to have it specified as January 1 through January 31. I can do that in code behind it. I could use a combo, and just enter ...
34
9287
by: prosoft | last post by:
When I use Dim myDTFI As DateTimeFormatInfo = New CultureInfo("he-IL", True).DateTimeFormat Dim strhmon1 As String = (myDTFI.GetMonthName(hmon1)) MsgBox(strhmon1) I get the local name of the gregorian month. How do I get the local name of the local month ? Tia
6
3267
by: Zeba | last post by:
Hi, I have a page with a calendar and two datalist items - one containing month values and the other, year values. Depending on the month/year value chosen ( in text/string format ) I should be able to display the correct month of the calendar. I thought it would be possible to use the OnSelectedIndexChanged attribute of the dropdown list to call a javascript function that sets the month value of the calendar...Something like :
10
4371
by: YvesDM | last post by:
Hi, How can I do this, I've got a little form with a dropdown. <select name="maand"> <option value='1'>januari</option> <option value='2'>februari</option> <option value='3'>maart</option> <option value='4'>april</option>
3
5722
by: gmazza via AccessMonster.com | last post by:
Hi there, I am trying to run a report using a parameter for where the user chooses a month from a combo box. Then on the report, I want it to compare the month to a date field and choose only those dates with the month chosen from the parameter form. Basically, its to see who's birthdays are coming up. So on the parameter form you choose November, so then I want the report to display all the kids who's birthdays are in November. Any help...
3
3010
by: One | last post by:
Hi group - I want to do a SELECT based on a date range - but mySQL syntax expects the month range to be two digits. So I have converted the month to show the leading zero like this : $next_month = date('m')+1; $this_month = date('m'); $pre_month = date('m')-1;
0
8324
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,...
0
8740
jinu1996
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...
1
8513
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6176
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 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...
0
5642
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();...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2742
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
2
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1733
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.