Im buildin an app for creating registers in an sql table, i have to select the data from datagriviews and put it on another datagridview, then i took the from the final datagriview to a class and im trying to send the data from the class to a SQL Server table, the code doens not show me any errors but i can not see the new row on the table
- private void button1_Click_1(object sender, EventArgs e) {
- int rowindex3 = dataGridView3.CurrentCell.RowIndex;
-
- Class1 d1 = new Class1();
- d1.CodigoEmpresa = dataGridView3.Rows[rowindex3].Cells[0].FormattedValue.ToString();
- d1.Inventario = dataGridView3.Rows[rowindex3].Cells[1].FormattedValue.ToString();
- d1.CodigoArticulo = dataGridView3.Rows[rowindex3].Cells[2].FormattedValue.ToString();
- d1.Partida = dataGridView3.Rows[rowindex3].Cells[3].FormattedValue.ToString();
- d1.CodigoAlmacen = dataGridView3.Rows[rowindex3].Cells[4].FormattedValue.ToString();
- d1.TipoUnidadMedida_ = dataGridView3.Rows[rowindex3].Cells[5].FormattedValue.ToString();
- d1.UnidadesStock = dataGridView3.Rows[rowindex3].Cells[6].FormattedValue.ToString();
- d1.UnidadesStock1_ = dataGridView3.Rows[rowindex3].Cells[7].FormattedValue.ToString();
- d1.PrecioMedio = dataGridView3.Rows[rowindex3].Cells[8].FormattedValue.ToString();
- d1.FechaCreacion = dataGridView3.Rows[rowindex3].Cells[9].FormattedValue.ToString();
- d1.PrecioNuevo = dataGridView3.Rows[rowindex3].Cells[10].FormattedValue.ToString();
- d1.FechaCaducidad = dataGridView3.Rows[rowindex3].Cells[11].FormattedValue.ToString();
- d1.PrecioNuevo1_ = dataGridView3.Rows[rowindex3].Cells[12].FormattedValue.ToString();
- d1.PrecioMedio1_ = dataGridView3.Rows[rowindex3].Cells[13].FormattedValue.ToString();
- d1.DescripcionArticulo = dataGridView3.Rows[rowindex3].Cells[14].FormattedValue.ToString();
- d1.Fecha = dataGridView3.Rows[rowindex3].Cells[15].FormattedValue.ToString();
- try {
-
- using(SqlConnection openCon = new SqlConnection("Data Source=OscarJCPL;Initial Catalog=Zthotel;Integrated Security=True")) {
- string saveStaff = "INSERT into Inventarios (CodigoEmpresa,Inventario,CodigoArticulo,Partida,CodigoAlmacen,TipoUnidadMedida_,UnidadesStock,UnidadesStock1_,PrecioMedio,FechaCreacion,PrecioNuevo,FechaCaducidad,PrecioNuevo1_,PrecioMedio1_,DescripcionArticulo,Fecha) VALUES (@CodigoEmpresa,@Inventario,@CodigoArticulo,@Partida,@CodigoAlmacen,@TipoUnidadMedida_,@UnidadesStock,@UnidadesStock1_,@PrecioMedio,@FechaCreacion,@PrecioNuevo,@FechaCaducidad,@PrecioNuevo1_,@PrecioMedio1_,@DescripcionArticulo,@Fecha)";
-
- using(SqlCommand querySaveStaff = new SqlCommand(saveStaff)) {
- querySaveStaff.Connection = openCon;
- querySaveStaff.Parameters.Add("@CodigoEmpresa", SqlDbType.SmallInt, 30).Value = CodigoEmpresa;
- querySaveStaff.Parameters.Add("@Inventario", SqlDbType.VarChar, 30).Value = Inventario;
- querySaveStaff.Parameters.Add("@CodigoArticulo", SqlDbType.VarChar, 30).Value = CodigoArticulo;
- querySaveStaff.Parameters.Add("@Partida", SqlDbType.VarChar, 30).Value = Partida;
- querySaveStaff.Parameters.Add("@CodigoAlmacen", SqlDbType.VarChar, 30).Value = CodigoAlmacen;
- querySaveStaff.Parameters.Add("@TipoUnidadMedida_", SqlDbType.VarChar, 30).Value = TipoUnidadMedida_;
- querySaveStaff.Parameters.Add("@UnidadesStock", SqlDbType.Decimal, 30).Value = UnidadesStock;
- querySaveStaff.Parameters.Add("@UnidadesStock1_", SqlDbType.Decimal, 30).Value = UnidadesStock1_;
- querySaveStaff.Parameters.Add("@PrecioMedio", SqlDbType.Decimal, 30).Value = PrecioMedio;
- querySaveStaff.Parameters.Add("@FechaCreacion", SqlDbType.DateTime, 30).Value = FechaCreacion;
- querySaveStaff.Parameters.Add("@PrecioNuevo", SqlDbType.Decimal, 30).Value = PrecioNuevo;
- querySaveStaff.Parameters.Add("@FechaCaducidad", SqlDbType.DateTime, 30).Value = FechaCaducidad;
- querySaveStaff.Parameters.Add("@PrecioNuevo1_", SqlDbType.Decimal, 30).Value = PrecioNuevo1_;
- querySaveStaff.Parameters.Add("@PrecioMedio1_", SqlDbType.Decimal, 30).Value = PrecioMedio1_;
- querySaveStaff.Parameters.Add("@DescripcionArticulo", SqlDbType.VarChar, 30).Value = DescripcionArticulo;
- querySaveStaff.Parameters.Add("@Fecha", SqlDbType.DateTime, 30).Value = Fecha;
- openCon.Open();
- }
- }
- MessageBox.Show("Registro Correcto");
- } catch {
- MessageBox.Show("Recuerde Seleccionar el Registro");
- }
- }