Skip to content

Sql query

romasha ali

Asked Oct 27, 2013, 1:02 PM EDT1 answer
Share
LinkedInX
below is my code that showing db data on label but i wanted to a search bar which take specified column data and then show on that row data on labels
like: i give teacher name on search bar and then only that teacher data will show on labels
guide me please



 protected void Button1_Click1(object sender, EventArgs e)
        {
             string intero = "Select * from Faculty";
            SqlCommand cmd = new SqlCommand(intero, con);

            SqlDataReader rdr;

            rdr = cmd.ExecuteReader();

           
            while (rdr.Read())
            {


                Lbl1.Text += rdr[0] + "" + rdr[1] + "
";
            }

            rdr.Close();
            con.Close();

        }

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    There are two ways to apply teacher filter.

    1. You can search data from SQL based on selected teacher name. So you need to modify your query to:
          string intero = "Select * from Faculty where TeacherName = '" + txtTeacherName.Text + "'";

    Based on your requirement you can apply LIKE operation as well.

    2. The another way is you fetch all the data but display the record which matches your search criteria:

      while (rdr.Read())
                {

                    if(rdr[0] == txtTeacherName.Text )
                    {
                            Lbl1.Text += rdr[0] + "" + rdr[1] + "
    ";
                            exit;
                    }
                }
    0