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();
}
Loading
Jyoti KhanchandaniPosted Oct 27, 2013, 8:22 PM
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;
}
}