0

我试图通过选择下拉列表项将整数值从 db 加载到文本框。我没有收到任何错误,但该值未显示在文本框中。这是我写的代码,请纠正我,

public void SiteNo()
    {
        Conhr.Open();
        //int anInteger;
        //anInteger = Convert.ToInt32(TextBox1.Text);
        //anInteger = int.Parse(TextBox1.Text);

        string sq = "select SiteCode from tbl_SiteMaster where  Sitealiasname='" + ddlsite.SelectedItem.Text + "' ";
        SqlCommand d = new SqlCommand(sq, Conhr);
        SqlDataReader r;
        r = d.ExecuteReader();
        while (r.Read())
        {
            TextBox1.Text = r.GetValue(0).ToString();
        }
        r.close();
        Conhr.Close();
    }
4

1 回答 1

0
//change code to this to find the problem

public void SiteNo()
{
    Conhr.Open();
    //int anInteger;
    //anInteger = Convert.ToInt32(TextBox1.Text);
    //anInteger = int.Parse(TextBox1.Text);

    string sq = "select count(SiteCode) from tbl_SiteMaster where  Sitealiasname='" + ddlsite.SelectedItem.Text + "' ";
    SqlCommand d = new SqlCommand(sq, Conhr);
    SqlDataReader r;
    r = d.ExecuteReader();
    while (r.Read())
    {
        TextBox1.Text = r.GetValue(0).ToString();
    }
    r.close();
    Conhr.Close();
}
于 2012-06-02T06:31:23.877 回答