edittted:
I already debug, I figure out that once I fill all the fields, autmatically generate a new row empty, and once it is stored in the dabase, it follow with the loop foreach, and automaticaly detect null reference this is an image, I hope you understand me img8.imageshack.us/i/error3xh.jpg
I need your help, I can’t control the exception,here is my method and the error say System.NullReferenceException: Object reference not set to an instance of an object”, how can I fix it, control the exeption, no more messages of this type?, no matter how its the structure : the error is the line ** if (combo3 == null || combo4 == null) **

private void btnCronograma_Click(object sender, EventArgs e)
{
string connstring = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\amaury\\Documents\\TEC\\Septimo Semestre\\Administracion de proyectos de ingenieria de softwaere\\nuevo4\\nuevo\\Office\\Office\\Policias.accdb";
using (OleDbConnection conn = new OleDbConnection(connstring))
{
conn.Open();
string sql = "INSERT INTO IndicadorProyecto (idProyecto, idMes, meta, real) VALUES(@idProyecto , @idMes , @meta, @real)";
OleDbCommand cmd = new OleDbCommand(sql, conn);
foreach (DataGridViewRow row in dataGridView8.Rows)
{
DataGridViewComboBoxCell combo3 = row.Cells["idProyecto"] as DataGridViewComboBoxCell;
DataGridViewComboBoxCell combo4 = row.Cells["idMes"] as DataGridViewComboBoxCell;
if (combo3 == null || combo4 == null)
{
MessageBox.Show("No se pudo convertir");
continue;
}
int idProyecto = int.Parse(combo3.Value.ToString());
int idMes = int.Parse(combo4.Value.ToString());
int meta = int.Parse(row.Cells[3].Value.ToString());
int real = int.Parse(row.Cells[4].Value.ToString());
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@idProyecto", idProyecto);
cmd.Parameters.AddWithValue("@idMes", idMes);
cmd.Parameters.AddWithValue("@meta", meta);
cmd.Parameters.AddWithValue("@real", real);
cmd.ExecuteNonQuery();
}
}
}
this is the complete error
Consulte el final de este mensaje para
obtener más detalles sobre cómo
invocar a la depuración Just-In-Time
(JIT) en lugar de a este cuadro de
diálogo.************** Texto de la excepción ************** System.NullReferenceException:
Referencia a objeto no establecida
como instancia de un objeto. en
Office.Form1.btnCronograma_Click(Object
sender, EventArgs e) en
C:\Users\amaury\Documents\TEC\Septimo
Semestre\Administracion de proyectos
de ingenieria de
softwaere\nuevo4\nuevo\Office\Office\Form1.cs:línea
726 en
System.Windows.Forms.Control.OnClick(EventArgs
e) en
System.Windows.Forms.Button.OnClick(EventArgs
e) en
System.Windows.Forms.Button.OnMouseUp(MouseEventArgs
mevent) en
System.Windows.Forms.Control.WmMouseUp(Message&
m, MouseButtons button, Int32 clicks)
en
System.Windows.Forms.Control.WndProc(Message&
m) en
System.Windows.Forms.ButtonBase.WndProc(Message&
m) en
System.Windows.Forms.Button.WndProc(Message&
m) en
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&
m) en
System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&
m) en
System.Windows.Forms.NativeWindow.Callback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr
lparam)
I think most likely cause is that
row.Cells[3].Valueorrow.Cells[4].Valueare null (since you have not given them a value) and.ToString()throws a null exception.Change the code to: