Solved

visual studio 2012 data grid view  checked list box usage

Posted on 2016-08-10
3
27 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 79

Accepted Solution

by:
David Johnson, CD, MVP earned 500 total points
ID: 41751489
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
ID: 41751670
Thanks a lot David Sir. I will try suggested solution and will revert if any further assistance required.
0
 

Author Comment

by:Nash Bawz
ID: 41752075
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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 …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

803 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