string IdDB = "select transid from transtbl where fullname = '"+textBox6.Text+"'";
con.SelectRec(IdDB, dt);
string IdDB2 = dt.Rows[0].ItemArray[0].ToString();
for (int rows = 0; rows < dataGridView2.Rows.Count; rows++)
{
int pProdID = int.Parse(dataGridView2.Rows[rows].Cells[0].Value.ToString());
string pProdName = dataGridView2.Rows[rows].Cells[1].Value.ToString();
double pPrice = double.Parse(dataGridView2.Rows[rows].Cells[2].Value.ToString());
int qQty = int.Parse(dataGridView2.Rows[rows].Cells[3].Value.ToString());
double tttTotal = double.Parse(dataGridView2.Rows[rows].Cells[4].Value.ToString());
string transdltdSql = "Insert into transdetailedtbl (transID, ProdID, ProdPrice, Qty, Total) value ("+int.Parse(IdDB2)+","+pProdID+","+pPrice+","+qQty+","+tttTotal+")";
con.ModRec(transdltdSql);
}
我收到错误
是的,请帮助我。我试图在for循环中执行查询,但是我得到的值来自gridview。System.NullReferenceException未处理 的HResult = -2147467261 Message =对象引用未设置为对象的实例。
答案 0 :(得分:0)
int pProdID = Convert.ToInt32(dataGridView2.Rows[rows].Cells[0].Value);
而不是这个
int pProdID = int.Parse(dataGridView2.Rows[rows].Cells[0].Value.ToString());