Search using textbox value and wildcard character

Total Post:134

Points:940
C#
 1506  View(s)
Ratings:
Rate this:

I want to search the empid of a name that with the characters entered in my textbox. using wildcard characters. I wrote the statement

da = new SqlDataAdapter(

 "Select empID from emp where FirstName like ' "+textbox1.text+" ' % "

   , connstring);

da.Fill(ds);

Is this statement correct?

  1. Post:378

    Points:2694
    Re: Search using textbox value and wildcard character

    string sql = "SELECT empID " +            
    "FROM emp " +              
    "WHERE FirstName like @FirstName";
    using(var con = new SqlConnection(connstring))
    using (SqlCommand command = new SqlCommand(sql, con))
    {
        command.Parameters.AddWithValue("@FirstName",  textbox1.text + "%");
        using(var da = new SqlDataAdapter(command))
        {
            da.Fill(ds);
        }
    }

      Modified On Apr-05-2018 04:55:40 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!