How are you thinking to get the value from the user?
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 188
Skill Endorsements: 3
OK. So you have a number that represents the month.
Then your query should use DATEPART to get the month number of the birth date stored in your DB.
Something like this SELECT [Name], [Date] FROM [Birthdays] WHERE DATEPART(month, [Date]) = @Month .
[Edit] Check out DATEPART here.
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 188
Skill Endorsements: 3
Your query uses the string name for the month. I generally try to avoid using strings for dates as there are always regional differences (i.e. language, ordering of each part, etc.).
However, your query is in a procedure so you need to set the SQLCommand object to call the procedure with your parameters.
Something like this.
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "dbo.MonthlyBirthday";
cmd.Parameters.AddWithValue("@BirthMonth", "Janvier"); // assuming that your DB is in French!
Also, given that your ComboBox shows the text value for the month then you just need to get the SelectedValue instead of the SelectedIndex.
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 188
Skill Endorsements: 3
"where have i used string for the date?"
@BirthMonth varchar(50)
"what is cmd?"
cmd is an SqlCommand object which should be obvious from the preceding text.
"where do i have to write the code"
Where ever it is that you need to call the Sql procedure.
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 188
Skill Endorsements: 3
@BirthMonth is the user input value as 1, 2 3, ... 12
Yes, but the procedure you posted expects @BirthMonth to be of type varchar(50)!
Last time I checked that is a text type.
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 188
Skill Endorsements: 3
Do you not think that int would be more appropriate?
Then the comparison month( [DOB]) = @BirthMonth would not need to do any type conversions.
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 188
Skill Endorsements: 3
how do i write the rest of the code
Add a parameter like I did in my previous post (only use the int value from your ComboBox).
Then execute the query as you would any other Table query.
[Edit]
Don't forget to modify the SQL procedure to ... @BirthMonth int
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 188
Skill Endorsements: 3
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 188
Skill Endorsements: 3