//METODO PARA INSERTAR UN NUEVO REGISTRO EN LA BASE DE DATOS public int agregarNuevoRegistro(object elNuevoRegistro) { //convertimos nuestro objeto generico a uno de la clase CAT_SUCURSALES objetoTablaSucursal = (CAT_SUCURSALES)elNuevoRegistro; //preparamos el commando de MySQL comandoMySQL = new MySqlCommand(); //preparar el dataset dsSucursales = new DataSet(); //preparar el dataAdapter... datAdapterMySQL = new MySqlDataAdapter(); //Establecer la conexion comandoMySQL.Connection = oBasedeDatos.miConectorNET; oBasedeDatos.establecerConexionNET(); //ARMAR la instruccion MYSQL: insert instruccionSQL = "INSERT INTO cat_sucursales (" + "codigo, nombre_sucursal, direccion, responsable" + ") VALUES ( " + pcs(objetoTablaSucursal.Codigo) + "," + pcs(objetoTablaSucursal.Nombre_sucursal) + "," + objetoTablaSucursal.Direccion.ToString() + "," + objetoTablaSucursal.Responsable.ToString() + " ) "; comandoMySQL.CommandText = instruccionSQL; int resultadodelComando = comandoMySQL.ExecuteNonQuery(); if (resultadodelComando <= 0) { return(0); //HAY UN ERROR } return(1); }
public void ENVIAR_DATOS_NUEVO_REGISTRO() { int i = 0; //NUEVO OBJETO DE LA CLASE PRODUCTO de la carpeta BO (Cat_productos) CAT_SUCURSALES oSucursal = new CAT_SUCURSALES(); //Nuevo OBJETO DE LA CLASE DAO_producto de la carpeta DAO DAO_sucursales oSucursalDAO = new DAO_sucursales(); //LLENAR PROPIEDADES DEL OBJETO PRODUCTO, CON CADA DATO CAPTURADO EN LA PANTALLA //Objeto.Propiedad = Pantalla.ComponenteVisual.Valor; oSucursal.Codigo = this.codigosuc.Text.Trim(); oSucursal.Nombre_sucursal = this.nombresuc.Text.Trim(); oSucursal.Direccion = this.direcc.Text.Trim(); oSucursal.Responsable = this.resp.Text.Trim(); //LLAMAMOS AL METODO DE LA CLASE DAO QUE HACE EL INSERT, le enviamos como parametro el objeto oProducto que //ya llenamos con los valores de la pantalla i = oSucursalDAO.agregarNuevoRegistro(oSucursal); //VERIFICAMOS SI SE HA EJECUTADO CORRECTAMENTE LA ACCION SOLICITADA if (i == 0) { MessageBox.Show("El proceso no se pudo realizar"); } else { MessageBox.Show("El proceso se genero con éxito"); } //MATAMOS A LOS OBJETOS UTILIZADOS oSucursal = null; oSucursalDAO = null; }