我不斷收到錯誤「的NullReferenceException是未處理的,未將對象引用設置到對象的實例」上線5的ExecuteScalar錯誤
1. Private void textbox1_TextChanged(object sender,EventArgs e)
2 {
3. SqlConnection cn=new SqlConnection("Connection string");
4. String sql ="select name from bank_info where account_no ='"+textbox1.Text+"'";
5. SqlCommand cmd =new SqlCommand(sql,cn);
6. Cn.Open();
7. String s1 = cmd.ExecuteScalar().ToString();
8. TextBox2.Text =s1.ToString();
是新來programming.Thanks
該錯誤「NullReferenceException未處理」。甚至沒有接近你在該代碼中的唯一錯誤 –
還有什麼其他錯誤? – user1568350
你明白人們輸入的速度非常快,並且你每次在文本框中改變文本時都試圖建立一個連接到數據庫 - 對於其他錯誤,來自@Mr Moose的答案修復了這些修復了大多數錯誤的 –