[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

visual studio 2012 data grid view  checked list box usage

Posted on 2016-08-10
3
Medium Priority
?
56 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 83

Accepted Solution

by:
David Johnson, CD, MVP earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

649 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