Vous êtes sur la page 1sur 1

using System.Data.

SqlClient;
int id;
string ruc, nom, dire, tele;
string coneccion = "Data Source=.;Initial Catalog=SistemitaFact;Integrated Security=True";
SqlConnection cn;
SqlDataAdapter da;
DataTable dt;
string consulta;
SqlCommand cmd;
bool esnuevo;
private void CargarDatos() {
consulta = "select * from Categorias where NombreCate like '%" + txtBuscar.Text + "%'";
SqlConnection cn = new SqlConnection(coneccion);
cn.Open();
da = new SqlDataAdapter(consulta, cn);
dt = new DataTable();
da.Fill(dt);
dtgbDatos.DataSource = dt;
cn.Close(); }
void Relleno(){
cmd.Connection = cn;
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
CargarDatos();
ContarRegistro(); }
private void btnNuevo_Click(object sender, EventArgs e) {
esnuevo = true; }
private void btnGuardar_Click(object sender, EventArgs e) {
if (txtNombre.Text != "") {
nom = txtNombre.Text;
cn = new SqlConnection(coneccion);
cmd = new SqlCommand();
cmd.CommandType = cmd.CommandType;
if (esnuevo == true)
cmd.CommandText = "Insert into Categorias(NombreCate)Values('" + nom + "')";
else {
id = int.Parse(txtIdentidad.Text);
cmd.CommandText = "Update Categorias Set NombreCate='" + nom + "'Where IdCate='" + id + "'"; }
} else MessageBox.Show("Los Datos marcados con(*) son OBLIGATORIOS"); }
private void btnCancelar_Click(object sender, EventArgs e) {
CargarDatos(); }
private void btnEliminar_Click(object sender, EventArgs e) {
DialogResult r = MessageBox.Show("Estas Seguro de Eliminar", "Alerta",
MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (DialogResult.Yes == r) {
cn = new SqlConnection(coneccion);
cmd = new SqlCommand();
cmd.CommandType = cmd.CommandType;
id = int.Parse(txtIdentidad.Text);
cmd.CommandText = "Delete Categorias Where IdCate='" + id + "'";
} }
private void dtgbDatos_SelectionChanged(object sender, EventArgs e) {
if (dtgbDatos.SelectedRows.Count > 0) {
txtIdentidad.Text = dtgbDatos.CurrentRow.Cells["IdCate"].Value.ToString();
txtNombre.Text = dtgbDatos.CurrentRow.Cells["NombreCate"].Value.ToString();
} else {
LimpiarTexto();
} }

Vous aimerez peut-être aussi