0% found this document useful (0 votes)
36 views2 pages

Namespace Producto

This document contains code for a C# Windows Form application that manages product data. It defines a form class with methods to display products in a data grid view by querying a database, clear input fields, and add a new product to the database by executing an insert statement when a button is clicked.

Uploaded by

Lupita Vega
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views2 pages

Namespace Producto

This document contains code for a C# Windows Form application that manages product data. It defines a form class with methods to display products in a data grid view by querying a database, clear input fields, and add a new product to the database by executing an insert statement when a button is clicked.

Uploaded by

Lupita Vega
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

namespace Producto

{
public partial class frmProducto : Form
{
public frmProducto()
{
InitializeComponent();
}
void Mostrar()
{
string ubic;
ubic = "Data source= ; Initial Catalog=dbSanMartin; User Id=sa;
Password=123";
SqlConnection conex = new SqlConnection(ubic);
conex.Open();
string tabP;
tabP = "selec IdProducto as 'Codigo', Descripcion, Unidmed as 'Med',
PreVent as 'Precio Venta'";
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(tabP, conex);
da.Fill(dt);
dgvProducto.DataSource = dt;
}
private void button1_Click(object sender, EventArgs e)
{

private void btnNuevo_Click(object sender, EventArgs e)


{
txtCodigo.Focus();
txtCodigo.Clear();
txtMedida.Clear();
txtMarca.Clear();
txtModelo.Clear();
txtLinea.Clear();
txtPrcVenta.Clear();
txtTipo.Clear();
txtUndMed.Clear();
}

private void btnEliminar_Click(object sender, EventArgs e)


{

private void btnGrabar_Click(object sender, EventArgs e)


{
string ncod, nmed, nmar, nmod, nlin, npre, ntip, nuni;
ncod = txtCodigo.Text;
nmed = txtMedida.Text;
nmar = txtMarca.Text;
nmod = txtModelo.Text;
nlin = txtLinea.Text;
npre = txtPrcVenta.Text;
ntip = txtTipo.Text;
nuni = txtUndMed.Text;
string ubic, grab;
ubic = "Data source= ; Initial Catalog=dbSanMartin; User Id=sa;
Password=123";
SqlConnection conex = new SqlConnection(ubic);
conex.Open();
grab="Insert into Producto values('"+ncod+ "';'"+nmed nmod nmar +"';'" +
nuni + "';'" + npre + "')";
SqlCommand etp = new SqlCommand(ubic, grab);
etp.ExecuteNonQuery();
MessageBox.Show("El nuevo producto se ingreso con exito al sistema de
Llantas San Martin");
Mostrar();
btnNuevo.Enabled = true;
btnGrabar.Enabled = false;

}
}
}

You might also like