I have some textbox to send one word to sql database. i want to fine this word in a coulmn that holding few words. i cant figure it out what the correct queary iv'e try the LIKE statement in many ways but still nothing. The word can be at the first, middle or the end of the line. for example: the user write "sun" and in the DB table there is an addres: "Johnson Blvd 3647 sun corner, CA" because there is the word "sun" this record will show on.

the code is:

private void button3_Click(object sender, EventArgs e)
        {
            ShowbillboardsByNumber.Clear();
            SqlConnection sqlcon = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["forumArtDatabase"]);
            SqlCommand sqlcmd = new SqlCommand("SELECT * FROM orders WHERE billBoardNumber LIKE @p1", sqlcon);
            sqlcmd.Parameters.Add(new SqlParameter("@p1", SqlDbType.VarChar)).Value = billBoardNumber.Text;
            sqlcon.Open();
            SqlDataAdapter da = new SqlDataAdapter(sqlcmd);
            da.Fill(ShowbillboardsByNumber);
            dgByNumber.DataSource = ShowbillboardsByNumber;
            sqlcon.Close();
        }

Recommended Answers

All 2 Replies

You need to wrap the search terms in %'s -- that is the MSSQL wild care.

sqlcmd.Parameters.Add(new SqlParameter("@p1", SqlDbType.VarChar)).Value = "%" + billBoardNumber.Text + "%";

God bless you. thank you very much

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.