Click here to Skip to main content
15,887,822 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i am using textbox in website for searching purpose from database like all other website
how can i do it
Posted
Comments
Kornfeld Eliyahu Peter 26-Feb-14 3:06am    
Have you done anything so far? Show some effort (code or searching)! As is it ain't a question...

1 solution

Try:
C#
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand cmd = new SqlCommand("SELECT iD, description FROM myTable WHERE searchColumn LIKE '%' + @SV + '%'", con))
        {
        cmd.Parameters.AddWithValue("@SV", mySearchTextBox.Text);
        using (SqlDataReader reader = cmd.ExecuteReader())
            {
            while (reader.Read())
                {
                int id = (int) reader["iD"];
                string desc = (string) reader["description"];
                Console.WriteLine("ID: {0}\n    {1}", iD, desc);
                }
            }
        }
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900