Solved

visual studio 2012 data grid view  checked list box usage

Posted on 2016-08-10
3
32 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 80

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
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…

733 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