0

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();
        }

Edited by John A: fixed code tags

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by elidotnet
0

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 + "%";
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.