我試圖將數據加載到文本框中,同時選擇下拉列表,我創建了一個用於檢索的類,並在下拉列表中將所選的索引更改爲名稱。但我無法得到我想要的答案。如果我已經在按鈕單擊事件中調用該類,它已正常工作。所以請糾正我。我犯了一個錯誤。這是我的代碼:從數據庫中檢索C#數據錯誤
public void so()
{
con.Open();
string s2;
s2 = "select Source from tbl_component where Componetcode='" + Mcodeddl.SelectedItem.Text + "'";
SqlCommand c2 = new SqlCommand(s2, con);
SqlDataReader d2;
d2 = c2.ExecuteReader();
while (d2.Read())
{
TextBox1.Text = d2["Source"].ToString().Trim();
}
d2.Close();
con.Close();
}
//i have called the so class here
protected void Mcodeddl_SelectedIndexChanged(object sender, EventArgs e)
{
so();
}
什麼是錯誤報告? –
查詢Componetcode在* Componentcode *中是否存在拼寫錯誤?然後你需要詢問注入 –
有什麼例外?你有沒有調試過你的代碼? – Talha