Home > DeveloperSection > Forums > Search using textbox value and wildcard character
Tanuj Kumar

Total Post:134

Points:940
Posted on    August-29-2014 1:12 AM

 C#
Ratings:


 1 Reply(s)
 969  View(s)
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?



Sumit Kesarwani

Total Post:378

Points:2694
Posted on    September-01-2014 12:18 AM

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

    }

}


Don't want to miss updates? Please click the below button!

Follow MindStick