8 AGENDA WappC# Prog Inserta, Consulta, Act
8 AGENDA WappC# Prog Inserta, Consulta, Act
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace WindowsFormsApplication2
{
class cls_conexion
{
SqlConnection sqlcon;
public cls_conexion()
{
sqlcon = new SqlConnection("Data Source=INGFREDDYSANTOS\\SQLEXPRESS;Initial
Catalog=agendadb;Integrated Security=True");
}
return sqlcon;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
class cls_datos : cls_conexion
{
#region DATOS
string query = "";
SqlCommand command;
cls_conexion conexion = new cls_conexion();
DataSet ds = new DataSet();
SqlDataAdapter adapter;
#endregion
public cls_datos()
{
try
{
command = new SqlCommand(query, conexion.sql_conectar());
command.ExecuteNonQuery();
conexion.sql_Desconectar();
}
catch (SqlException x)
{
MessageBox.Show(x.ToString());
}
try
{
command = new SqlCommand(query, conexion.sql_conectar());
command.ExecuteNonQuery();
conexion.sql_Desconectar();
}
catch (SqlException x)
{
MessageBox.Show(x.ToString());
}
}
}
}
______________________________________________________________________________________________
Form1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ejemplo.Formularios; // para usar formularios de la carpeta
[ FORMULARIOS ]
namespace ejemplo
{
public partial class FrmPrincipal : Form
{
public FrmPrincipal()
{
InitializeComponent();
}
Boton Insertar
private void btnInsert_Click(object sender, EventArgs e)
{
frmInsert insert = new frmInsert();
insert.Show();
}
Boton Consulta
private void btnConsulta_Click(object sender, EventArgs e)
{
frmConsulta consulta = new frmConsulta();
consulta.Show();
}
Boton Actualizar
private void btnActualizar_Click(object sender, EventArgs e)
{
frmActualizar actualizar = new frmActualizar();
actualizar.Show();
}
______________________________________________________________________________________________
Formulario Insertar
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class FrmInsertar : Form
{
cls_datos datos = new cls_datos();
public FrmInsertar()
{
InitializeComponent();
}
}
}
}
______________________________________________________________________________________________
Formulario consulta
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ejemplo.Clases;
namespace ejemplo.Formularios
{
public partial class frmConsulta : Form
{
cls_datos datos = new cls_datos();
public frmConsulta()
{
InitializeComponent();
}
Boton Buscar
Link Salir
}
}
______________________________________________________________________________________________
Formulario actualizar
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class FrmActualiza : Form
{
cls_datos datos = new cls_datos();
public FrmActualiza()
{
InitializeComponent();
}
txtCodigo.Enabled = true;
linkLabel1.Enabled = true;
txtCodigo.Focus();
if (data.Rows.Count != 0)
{
txtNombre.Text = data.Rows[0]["nombre"].ToString();
txtApellido.Text = data.Rows[0]["apellido"].ToString();
txtTelefono.Text = data.Rows[0]["telefono"].ToString();
txtCodigo.Enabled = false;
linkLabel1.Enabled = false;
}
}
}
}