for (int i = 0; i < dgvHead.Rows.Count; i++) { if (dgvHead.Rows[i].Cells[0].Value == null) { break; } string sql = "insert product_desProductTime (fno,positation,worktimeNo,initialCount,seamDistance,endCount,worktimeName,samTime,target,equipment,tool) values('" + txtfNo.Text + "','头部','" + dgvHead.Rows[i].Cells[0].Value.ToString() + "'," +Convert.ToInt32(dgvHead.Rows[i].Cells[1].Value) + ","+Convert.ToInt32(dgvHead.Rows[i].Cells[2].Value)+"," +Convert.ToInt32(dgvHead.Rows[i].Cells[3].Value) + ",'" + dgvHead.Rows[i].Cells[4].Value.ToString() + "'," + Convert.ToDouble(dgvHead.Rows[i].Cells[5].Value) + ","+Convert.ToDouble(dgvHead.Rows[i].Cells[6].Value) + ",'" + dgvHead.Rows[i].Cells[7].Value.ToString() + "','" + dgvHead.Rows[i].Cells[8].Value.ToString() + "')"; SqlHelp.ExecuteNonQuery(CommandType.Text, sql); }
为什么 我将datagridview中的数据写入到数据库的时候出现"对象不能从 DBNull 转换为其他类型。",虽然数据已经成功插入到DB中了