[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

visual studio 2012 data grid view  checked list box usage

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

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?

834 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