将搜索结果发布到文本框

问题描述:

我有一个问题,我尝试各种方式将搜索结果发布到文本框但总是不返回这是我的代码

hi guy i have a problem that i try every way to make Posting search results to textbox but always return nothing this is my code

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

      }



它的工作,当我创建断点时它会得到日期但没有任何显示

和我有另一个问题,我有4个COM盒填写表单负载

假设当我进行搜索它应该显示从搜索中选择的值,这将产生问题,因为它加载表单加载? ? PLZ帮助我真的想更多,但仍然需要通过Windows窗体体验非常感谢


its work and when i make breakpoints it gets date but nothing display
and i have another problem that i have got 4 com boxes which fill in form load
suppose when i make search it should display the value of selected from search and this will make problem because it loads with form load ?? plz help really i think more but still need experiences through windows form thanks a lot

while (dr.Read())
            {
if(dr.HasRows)
{
     txtemployee.Text = dr["EmpName"].ToString();
     txtExcutionOrder.Text = dr["ExcutionOrder"].ToString();

}
else
{
        MessageBox.Show("not found");
}
}


非常感谢问题出现在与此代码冲突的另一个代码中但是我需要知道通过搜索项目从选择顺序填充组合框