I have DatagridView on form.

My database has three fields.
- userId (bigint)
- userName (varchar)
- userDob (date)

Now, on Form I have comboBox, which lists Months (Jan, Feb, March and so on...). I want my program to work like this.

If I select any month on ComboBox, birthdays of clients related to that month should only be displayed in DatagridView. Help me how to do it.

add this to your query.

where userDob like '"+cbYear.Text+"-"+cbMonth.Text+"-%' order by userDob

example output: `where userDob like '2015-01-%' order by userDob`

the format of date is `yyyy-MM-dd`:


for `yyyy` represent 4 digit year.
    `MM` represent 2 digit month.
    `dd` represent 2 digit day.



Happy Programming and God Bless you.

If this is SQL Server then you could use the DATENAME method:

SELECT * FROM YourTable where DATENAME(month, YourDateField) = 'July'

In this way, you can select all records that match a month regardless of year which is what I believe you want.

commented: May be this will solve my problem... I'll try this code ASAP +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.