2014-03-13 1 views
0

데이터베이스의 테이블을 업데이트하고 있지만 지속적으로 예외가 발생합니다. NullReferenceException "개체 참조가 개체의 인스턴스로 설정되지 않았습니다."테이블 업데이트 중 예외 가져 오기

for (int i = 0; i < dataGridView1.Rows.Count; i++) 
{ 
    double bal_due, a, b; 
    a = double.Parse(dataGridView1.Rows[i].Cells[3].Value.ToString()); //this lines throws the exception 
    b= double.Parse(dataGridView1.Rows[i].Cells[4].Value.ToString()); 
    bal_due = a - b;       
    string var = string.Format(
     "update purchase_order set paid_today={0}, " + 
     "balance_due={1} where order_no={2}", 
     dataGridView1.Rows[i].Cells[4].Value, bal_due, comboBox2.SelectedValue); 
    obj.query(var); 
} 
+0

뭔가 잘못되었습니다. 어떤 라인이 예외를 던집니까? – Blorgbeard

+0

@ Blorgbeard ... 내가 업데이트 한 코드를 확인하십시오 –

+0

Cells [3] .Value는 아마도 null이고 ToString을 호출하고 있습니다. – DeveloperGuo

답변

0

나는 당신이 루프이 추가 ... 당신의 DataGridView에 하단의 빈 행에 대한 업데이 트 문을 실행하려고하는 것 같아요 :

를 내가 아래로 조각을 붙여 넣은

for (int i = 0; i < dataGridView1.Rows.Count; i++) 
{ 
    if (dataGridView1.Rows[i].IsNewRow) continue; 
    ... 
관련 문제