Click here to Skip to main content
15,891,895 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionMP3 structure Pin
haggenx27-Sep-07 12:36
haggenx27-Sep-07 12:36 
QuestionSaving and Loading forms from file? [modified] Pin
_Richard Faulkner_27-Sep-07 12:31
_Richard Faulkner_27-Sep-07 12:31 
AnswerRe: Saving and Loading forms from file? Pin
Paul Conrad30-Sep-07 13:41
professionalPaul Conrad30-Sep-07 13:41 
GeneralRe: Saving and Loading forms from file? Pin
_Richard Faulkner_1-Oct-07 15:45
_Richard Faulkner_1-Oct-07 15:45 
QuestionPopulating a dataGridView from a XML file Pin
Benny_Lava27-Sep-07 6:33
Benny_Lava27-Sep-07 6:33 
AnswerRe: Populating a dataGridView from a XML file Pin
Dave Kreskowiak27-Sep-07 7:26
mveDave Kreskowiak27-Sep-07 7:26 
QuestionCan any one short this Coding Pin
tharshini27-Sep-07 5:36
tharshini27-Sep-07 5:36 
AnswerRe: Can any one short this Coding Pin
Dave Kreskowiak27-Sep-07 7:21
mveDave Kreskowiak27-Sep-07 7:21 
Wow, there's a lof of stuff bad with this. Sigh | :sigh: OK.

Without doing anything to your database, which itself needs a redesign, you can build an SQL SELECT with and IN clause.

First, you don't need all the month* variables. Get rid of them.

Next, add a Tag value to each of your CheckBox's with the month name corresponding to each one. CheckBox1.Tag="'January'", CheckBox2.Tag="'Febuary'", ... (NOTE: The single quotes in those strings!)

Wire up all the CheckBox's CheckChanged events to the same handler. See the Handles clause at the end?? Add all of the CheckBox's to it.
Private Sub CheckBox_CheckChanged(blah, blah) Handles, CheckBox1.CheckChanged, CheckBox2.CheckChanged, ...


In this handler, cast the sender back to a CheckBox and get the Tag property from it. In an ArrayList collection, check to see if the Tag value is in the collection, if not, Remove it, else, Add it. A quick'n'dirty version of this would look something like:
Dim cb As CheckBox = DirectCast(sender, CheckBox)
If Not myMonthList.Contains(cb.Tag) Then
    myMonthList.Add(cb.Tag)
Else
    myMonthList.Remove(cb.Tag)
End If

Mind you, this code doesn't care if the checkbox is checked or not!! You might want to factor that into this code.

When you go to build the SQL query string, you'turn the collection of months, myMonthList in the above example, into a String of values seperated by commas, like this:
Dim months As String = String.Join(",", myMonthList.ToArray(GetType(String)))


You then make that list part of you SQL statement:
Dim sql As String = String.Format("SELECT * FROM Finacial_Request_Report WHERE year1='{0}' AND month1 IN ({1})", NumericUpDown1.Text, months)

You'll get a statement that looks something like this:
SELECT * FROM Financial_Request_Report WHERE year1=1980 AND month1 IN ('January','Febuary')


But, this is quick'n'dirty. A good solution would require you to redesign your database and scrap all the code you put up in your original post.




A guide to posting questions on CodeProject[^]

Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic
     2006, 2007


Questionhow to draw small rectangles in a rectangle using vb.net Pin
VB 8.027-Sep-07 5:02
VB 8.027-Sep-07 5:02 
AnswerRe: how to draw small rectangles in a rectangle using vb.net Pin
Dave Kreskowiak27-Sep-07 5:33
mveDave Kreskowiak27-Sep-07 5:33 
QuestionChecking for Admin rights Pin
archangel_2627-Sep-07 4:57
archangel_2627-Sep-07 4:57 
AnswerRe: Checking for Admin rights Pin
Dave Kreskowiak27-Sep-07 5:25
mveDave Kreskowiak27-Sep-07 5:25 
GeneralRe: Checking for Admin rights Pin
archangel_2627-Sep-07 5:51
archangel_2627-Sep-07 5:51 
GeneralRe: Checking for Admin rights Pin
Dave Kreskowiak27-Sep-07 6:50
mveDave Kreskowiak27-Sep-07 6:50 
AnswerRe: Checking for Admin rights Pin
ESTAN27-Sep-07 11:32
ESTAN27-Sep-07 11:32 
GeneralRe: Checking for Admin rights Pin
Dave Kreskowiak27-Sep-07 12:21
mveDave Kreskowiak27-Sep-07 12:21 
GeneralRe: Checking for Admin rights Pin
archangel_261-Oct-07 10:56
archangel_261-Oct-07 10:56 
GeneralRe: Checking for Admin rights Pin
Dave Kreskowiak2-Oct-07 7:14
mveDave Kreskowiak2-Oct-07 7:14 
GeneralRe: Checking for Admin rights Pin
archangel_262-Oct-07 9:19
archangel_262-Oct-07 9:19 
GeneralRe: Checking for Admin rights Pin
Dave Kreskowiak2-Oct-07 12:28
mveDave Kreskowiak2-Oct-07 12:28 
GeneralRe: Checking for Admin rights Pin
archangel_262-Oct-07 14:42
archangel_262-Oct-07 14:42 
GeneralRe: Checking for Admin rights Pin
Dave Kreskowiak2-Oct-07 15:05
mveDave Kreskowiak2-Oct-07 15:05 
GeneralRe: Checking for Admin rights Pin
archangel_262-Oct-07 15:16
archangel_262-Oct-07 15:16 
GeneralRe: Checking for Admin rights Pin
Dave Kreskowiak3-Oct-07 4:26
mveDave Kreskowiak3-Oct-07 4:26 
GeneralRe: Checking for Admin rights Pin
archangel_263-Oct-07 8:22
archangel_263-Oct-07 8:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.