none
Visual studio 2012 and Mysql RRS feed

  • Question

  • I am a beginner in Visual studio 2012 and making a data management programme with visual studio 2012 as front end and MySql as back end. I want to filter data grid view table with combo box , checked listbox and List box (multiple selected) . When I select one item it works fine and when I select multiple items in the List box I do not have code can u help me please. I am able to get all the items of a column in the list box/ checked list box/ combo box by following code

    Query = "Select * from `rrrr.data`.`trial` "
    COMMAND = New MySqlCommand(Query, MySqlConn)
    READER = COMMAND.ExecuteReader
    While READER.Read
    Dim sCountry = READER.GetString("COUNTRY")
    ListBox1.Items.Add(sCountry)
    End While

    But for filtering data when I use below query it does not work ( for multiple selected or more than one item ) Query which I use is-
    Query = "Select * from `rrrr.data`.`trial` Where `COUNTRY`in (''" & ListBox1.SelectedItem& "'' )"

    Kindly help me out  in filtering data using  combo box , checked list box and List box ,. my requirement is to filter data as per the selected column and multiple  selected items of the a selected column.
    • Moved by lake Xiao Thursday, August 11, 2016 1:58 AM
    Wednesday, August 10, 2016 5:01 AM

Answers

  • Hi,

    I see two important points:

    a) This is a minor item and it should not really change anything: In your query you are just checking for one element. But your query checks if the value is in (...). I would rewrite the query to check if the value is equal. (WHERE COUNTRY = ....)

    b) You create a query through string concatenation. That is something that you shouldn't do because it can cause a lot of trouble (SQL Injection attacks and formating problems). You should use parameters instead.
     ("WHERE COUNTRY = @country"). Then you can add the parameter with COMMAND.Parameters.AddWithValue("@country", ListBox1.SelectedItem);

    If this does not work then please give us details about the database and explain the required query in more detail.

    With kind regards,

    Konrad

    Wednesday, August 10, 2016 6:01 AM

All replies

  • Hi,

    I see two important points:

    a) This is a minor item and it should not really change anything: In your query you are just checking for one element. But your query checks if the value is in (...). I would rewrite the query to check if the value is equal. (WHERE COUNTRY = ....)

    b) You create a query through string concatenation. That is something that you shouldn't do because it can cause a lot of trouble (SQL Injection attacks and formating problems). You should use parameters instead.
     ("WHERE COUNTRY = @country"). Then you can add the parameter with COMMAND.Parameters.AddWithValue("@country", ListBox1.SelectedItem);

    If this does not work then please give us details about the database and explain the required query in more detail.

    With kind regards,

    Konrad

    Wednesday, August 10, 2016 6:01 AM
  • Hi Nashbaw,

    Since Our forum is discussing about VS general question like how to set/configure Visual Studio and Visual Studio tools.

    And your question is more related to the ADO.NET. I moved it to our ADO.NET forum for better support.

    https://social.msdn.microsoft.com/Forums/en-US/home?forum=adodotnetdataset

    Thanks for your understanding.

    Best Regards,

    Lake Xiao

    Thursday, August 11, 2016 1:52 AM