Using Like operator in Select query in MySQL

on Mar 27, 2019 11:45 PM


i am using this query on page load it is mysql,

it works fine, what i want is a keyword search on name column so if query string value Q=Weave so it should search in name column and show all the records which has Weave if query string is null so it should show all the data .

in MSSQL we do like select * from country where name like '%'+@Q +'%' and pass % to show all data and pass value to search the data but how to do in above mysql sceneriao pls advice

            string constr = ConfigurationManager.ConnectionStrings["locations"].ConnectionString;
            using (MySqlConnection con = new MySqlConnection(constr))
                using (MySqlCommand cmd = new MySqlCommand("SELECT * FROM locations where  "))
                    using (MySqlDataAdapter sda = new MySqlDataAdapter())
                        cmd.Connection = con;
                        sda.SelectCommand = cmd;
                        using (DataTable dt = new DataTable())
                            ListView1.DataSource = dt;


Download FREE API for Word, Excel and PDF in ASP.Net: Download