Example #1
0
        private void btnBuscar_Click(object sender, EventArgs e)
        {
            try
            {
                rTxtBxDescripcion.Text = "";
                lblPrecio2.Text        = "";

                interno.AbrirConexion();
                string        cod      = txtCodigo.Text;
                string        comand   = "select descripcion, precio from articulos where codigo=" + cod;
                SqlCommand    command  = new SqlCommand(comand, interno.Conexion);
                SqlDataReader registro = command.ExecuteReader();


                if (registro.Read())
                {
                    rTxtBxDescripcion.Text = registro["descripcion"].ToString();
                    lblPrecio2.Text        = "$" + registro["precio"].ToString();
                }
                else
                {
                    MessageBox.Show("Elemento no encontrado");
                }

                interno.CerrarConexion();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                interno.CerrarConexion();
            }
        }
Example #2
0
 private void btnAgregar_Click(object sender, EventArgs e)
 {
     try
     {
         obj.AbrirConexion();
         string     descripcion = txtDescripcion.Text;
         string     precio      = txtPrecio.Text;
         SqlCommand insercion   = new SqlCommand($"insert into articulos(descripcion, precio) values('{descripcion}',{precio})", obj.Conexion);
         insercion.ExecuteNonQuery();
         obj.CerrarConexion();
         txtDescripcion.Text = "";
         txtPrecio.Text      = "";
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }