Referencia a objeto no establecida como instancia
Estoy hacienedo un inset into dentro de un for me recorre y guarda el primer registro y hasta hay bien pero cuando esta recorriendo el segundo registro se va hay mismo para el catch (Exception) y me saca el error Referencia a objeto no establecida como instancia, soy mu nuevo en esto y de verdad que no he podido ver el problemas, este es el codigo ke tengo...
SqlConnection conex = new SqlConnection(conexion);
SqlCommand commmd = new SqlCommand();
conex.Open();
commmd.Connection = conex;
for (int i = 0; i < this.dtGrid.Rows.Count - 1; i++)
{
try
{
?
commmd.CommandText = "INSERT INTO tblDETARECEPORDECORTE(CODREMISION,IDCONSECUTIVO,ORDENCORTE,REFERENCIA," +
"talla, color, canttipoa, canttipob, cantidadr, pedido, cliente, tipomvto, tipodcto, nrodcto, usuario, cantidad)" +
"VALUES" +
"('" + this.txtRemision.Text + "'," + this.dtGrid.Rows.Cells[1].Value.ToString() + "," +
"'" + this.dtGrid.Rows.Cells[2].Value.ToString() + "'," +
"'" + this.dtGrid.Rows.Cells[3].Value.ToString() + "'," +
"'" + this.dtGrid.Rows.Cells[5].Value.ToString() + "'," +
"'" + this.dtGrid.Rows.Cells[4].Value.ToString() + "'," +
"'" + this.dtGrid.Rows.Cells[6].Value.ToString() + "'," +
"'" + this.dtGrid.Rows.Cells[7].Value.ToString() + "'," +
"'" + this.dtGrid.Rows.Cells[8].Value.ToString() + "'," +
"'" + this.dtGrid.Rows.Cells[10].Value.ToString() + "'," +
"'" + this.dtGrid.Rows.Cells[11].Value.ToString() + "'," +
"'" + this.toolMvto.Text + "','" + this.toolTipodcto.Text + "'," +
"" + this.txtMovimiento.Text + ",'" + this.toolUser.Text + "'," +
"" + this.dtGrid.Rows.Cells[9].Value.ToString() + ")";
contador = contador + 1;
commmd.ExecuteNonQuery();
?
}
catch (Exception eexx)
{
MessageBox.Show(("ERROR" + eexx.Message), "Maquila Internacional Confeccion");
}
}
SqlConnection conex = new SqlConnection(conexion);
SqlCommand commmd = new SqlCommand();
conex.Open();
commmd.Connection = conex;
for (int i = 0; i < this.dtGrid.Rows.Count - 1; i++)
{
try
{
?
commmd.CommandText = "INSERT INTO tblDETARECEPORDECORTE(CODREMISION,IDCONSECUTIVO,ORDENCORTE,REFERENCIA," +
"talla, color, canttipoa, canttipob, cantidadr, pedido, cliente, tipomvto, tipodcto, nrodcto, usuario, cantidad)" +
"VALUES" +
"('" + this.txtRemision.Text + "'," + this.dtGrid.Rows.Cells[1].Value.ToString() + "," +
"'" + this.dtGrid.Rows.Cells[2].Value.ToString() + "'," +
"'" + this.dtGrid.Rows.Cells[3].Value.ToString() + "'," +
"'" + this.dtGrid.Rows.Cells[5].Value.ToString() + "'," +
"'" + this.dtGrid.Rows.Cells[4].Value.ToString() + "'," +
"'" + this.dtGrid.Rows.Cells[6].Value.ToString() + "'," +
"'" + this.dtGrid.Rows.Cells[7].Value.ToString() + "'," +
"'" + this.dtGrid.Rows.Cells[8].Value.ToString() + "'," +
"'" + this.dtGrid.Rows.Cells[10].Value.ToString() + "'," +
"'" + this.dtGrid.Rows.Cells[11].Value.ToString() + "'," +
"'" + this.toolMvto.Text + "','" + this.toolTipodcto.Text + "'," +
"" + this.txtMovimiento.Text + ",'" + this.toolUser.Text + "'," +
"" + this.dtGrid.Rows.Cells[9].Value.ToString() + ")";
contador = contador + 1;
commmd.ExecuteNonQuery();
?
}
catch (Exception eexx)
{
MessageBox.Show(("ERROR" + eexx.Message), "Maquila Internacional Confeccion");
}
}
Respuesta de darkastaroth
1