0

我有这段代码从 SQL 获取返回查询并将其放在标签中。问题是,当我单击搜索按钮时,标签不会填充。但是当我进入调试模式时,它有值。这是为什么?!帮助!

//I've cut down the code here to make the question clearer
//But these 4 fields were all valid properties - Sayse
public string FirstName
public string MiddleName
public string LastName
public string Email

  public void SearchAffectedUser()
    {
        using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
        {

            using (SqlCommand com_retrieve = new SqlCommand("Reader.usp_SearchAffectedUser", con))
            {
                com_retrieve.CommandType = CommandType.StoredProcedure;
                com_retrieve.Parameters.Add("@fld_EmployeeId", SqlDbType.Int).Value = AffectedUser;
                con.Open();

                com_retrieve.ExecuteNonQuery();
                SqlDataReader dr = com_retrieve.ExecuteReader();
                if (dr.Read())
                {

                    FirstName = dr.GetValue(0).ToString();
                    MiddleName = dr.GetValue(1).ToString();
                    LastName = dr.GetValue(2).ToString();
                    Email = dr.GetValue(3).ToString();
                }

            }
        }
    }

  protected void findAffectedUserButton_Click(object sender, EventArgs e)
    {
        ticket.AffectedUser = affectedUserTextBox.Text;
        ticket.FirstName = firstNameValueLabel.Text;
        ticket.MiddleName = middleNameValueLabel.Text;
        ticket.LastName = lastNameValueLabel.Text;
        ticket.Email = emailValueLabel.Text;
        ticket.SearchAffectedUser();

    }
4

2 回答 2

3

首先设置用于搜索的 AffectedUser 属性,然后调用搜索命令,最后设置标签。

protected void findAffectedUserButton_Click(object sender, EventArgs e)
{
    ticket.AffectedUser = affectedUserTextBox.Text;
    ticket.SearchAffectedUser();
    firstNameValueLabel.Text = ticket.FirstName;
    middleNameValueLabel.Text = ticket.MiddleName;
    lastNameValueLabel.Text = ticket.LastName;
    emailValueLabel.Text = ticket.Email;

}
于 2013-07-26T07:40:22.697 回答
0

将标签TEXT属性设置为“”。

于 2013-07-26T07:54:45.010 回答