Solved

visual studio 2012 data grid view  checked list box usage

Posted on 2016-08-10
3
15 Views
Last Modified: 2016-08-11
I have four columns in data grid view. one of the coloumn name is country which has 15 countries name. These names are available in the checked list box. I only want to see the data of only three countries in data grid view for which I have selected checked list box. Kindly tell me the query for using in select statement to filter only these countries details in data grid view.
0
Comment
Question by:Nash Bawz
  • 2
3 Comments
 
LVL 78

Accepted Solution

by:
David Johnson, CD, MVP earned 500 total points
Comment Utility
you have to build your query item by item.
pseudo code
for each textbox in textboxlist {   if (textbox.checked) query += textbox.value }
if query.count = 0 then mquery = "select * from table"
else if  query.count = 1 then mquery = 'select * from table where country = query
else {
mquery = "select * from table where country =" + query"
for (counter =1 to counter -eq query.count) {
mquery += ' or country =' + query[counter]
}
}
sqlcmd mquery

Open in new window

0
 

Author Closing Comment

by:Nash Bawz
Comment Utility
Thanks a lot David Sir. I will try suggested solution and will revert if any further assistance required.
0
 

Author Comment

by:Nash Bawz
Comment Utility
David sir this my code but the suggested solution is not working,  can u plsc modify my code. If I select one check box it works fine , for  example if I select check box ( in checked list box) of US it filters  data and shows only US data in rows, but if I select US then UK then it shows data of  the last selected  check box  i.e  UK. I want to see the data of  both US and  UK as both the check  boxes  are selected.

 Private Sub CheckedListBox1_ItemCheck(sender As Object, e As ItemCheckEventArgs) Handles CheckedListBox1.ItemCheck
        Dim dbDataSet As New DataTable
        MySqlConn = New MySqlConnection
        MySqlConn.ConnectionString =
        "server = localhost;userid=root;password=5274;database=country.data"
        Dim SDA As New MySqlDataAdapter
        Dim bsource As New BindingSource

        Try
            MySqlConn.Open()
            Dim Query As String
            Query = "Select * from `country.data`.`trial` where  `COUNTRY` in  ('" & CheckedListBox1.Text & "' )"
            COMMAND = New MySqlCommand(Query, MySqlConn)
            SDA.SelectCommand = COMMAND
            SDA.Fill(dbDataSet)
            bsource.DataSource = dbDataSet
            Me.DataGridView2.DataSource = bsource
            SDA.Update(dbDataSet)
            MySqlConn.Close()
        Catch ex As MySqlException
            MessageBox.Show(ex.Message)
        Finally
            MySqlConn.Dispose()
        End Try
    End Sub
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now