private void btnNamesearch_Click(object sender, EventArgs e) { bool temp = false; SqlConnection con = new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Educational System;Data Source=DREAMS"); con.Open(); SqlCommand cmd = new SqlCommand("SELECT EmpName, ExcutionOrder FROM Employee WHERE EmpName ='" + txtusernameSearch.Text.Trim() + "'", con); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { txtemployee.Text = dr["EmpName"].ToString(); txtExcutionOrder.Text = dr["ExcutionOrder"].ToString(); temp = true; } if (temp == false) MessageBox.Show("not found"); con.Close(); dr.Close(); }
while (dr.Read()) { if(dr.HasRows) { txtemployee.Text = dr["EmpName"].ToString(); txtExcutionOrder.Text = dr["ExcutionOrder"].ToString(); } else { MessageBox.Show("not found"); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)