Using Like operator in Select query in MySQL

Last Reply 25 days ago By pandeyism

Posted 25 days ago

hello,

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())
                        {
                            sda.Fill(dt);
                            ListView1.DataSource = dt;
                            ListView1.DataBind();
                        }
                    }
                }
            }        

 

You are viewing reply posted by: pandeyism 25 days ago.