Práctica 15. Sistema de Biblioteca usando Access como base de datos
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;
using System.Data.OleDb;
namespace Práctica_15
{
public partial class Edición : Form
{
public Edición()
{
InitializeComponent();
}
private void Edición_Load(object sender, EventArgs
e)
{
}
int cont
= 0;
private void
btnAgregar_Click(object sender, EventArgs e)
{
//
Creando y cargando conexión y command
OleDbConnection
CANAL;
OleDbCommand
ORDEN;
//
Abriendo la conexión o enlace
CANAL = new OleDbConnection("Provider=Microsoft.JET.OLEDB.4.0;
Data Source=" + Application.StartupPath
+ "\\biblio.mdb");
// Creando y cargando un
objeto OleDbCommand
//
@variable es una variable de tipo parámetro
string q = "update libro
set autor=@AUTOR, titulo=@TITULO, subtitulo=@SUBTITULO, materia=@MATERIA,
editorial=@EDITORIAL, clasificacion=@CLASIFICACION, precio=@PRECIO where
clave=" + txtClave.Text;
ORDEN = new OleDbCommand(q,
CANAL);
ORDEN.Parameters.Add(new OleDbParameter ("@AUTOR",
OleDbType.VarWChar, 50));
ORDEN.Parameters["@AUTOR"].Value
= txtAutor.Text;
ORDEN.Parameters.Add(new OleDbParameter ("@TITULO",
OleDbType.VarWChar, 50));
ORDEN.Parameters["@TITULO"].Value = txtTítulo.Text;
ORDEN.Parameters.Add(new
OleDbParameter ("@SUBTITULO",
OleDbType.VarWChar, 50));
ORDEN.Parameters["@SUBTITULO"].Value
= txtSubT.Text;
ORDEN.Parameters.Add(new OleDbParameter
("@MATERIA", OleDbType.VarWChar, 50));
ORDEN.Parameters["@MATERIA"].Value
= txtMateria.Text;
ORDEN.Parameters.Add(new OleDbParameter ("@EDITORIAL",
OleDbType.VarWChar, 50));
ORDEN.Parameters["@EDITORIAL"].Value
= txtEditorial.Text;
ORDEN.Parameters.Add(new OleDbParameter ("@CLASIFICACION",
OleDbType.VarWChar, 50));
ORDEN.Parameters["@CLASIFICACION"].Value
= txtClasi.Text;
ORDEN.Parameters.Add(new OleDbParameter ("@PRECIO",
OleDbType.Double));
ORDEN.Parameters["@PRECIO"].Value = txtPrecio.Text;
ORDEN.Connection.Open();
ORDEN.ExecuteNonQuery();
ORDEN.Connection.Close();
//Limpiando
TextBox para otra inserción
txtAutor.Text= "";
txtTítulo.Text= "";
txtSubT.Text="";
txtMateria.Text="";
txtEditorial.Text="";
txtClasi.Text="";
txtPrecio.Text="";
txtClave.Text = "";
label9.Text = "Registro
modificado";
}
private void
txtAutor_TextChanged(object sender, EventArgs e)
{
}
private void
label1_Click(object sender, EventArgs e)
{
}
}
}
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;
using System.Data.OleDb;
namespace Práctica_15
{
public partial class Busqueda : Form
{
public Busqueda()
{
InitializeComponent();
}
private void
btnBuscar_Click(object sender, EventArgs e)
{
//objetos
oledb que se ocupan
OleDbConnection
CANAL;
DataSet TABLA;
OleDbDataAdapter
ORDEN;
CANAL = new OleDbConnection("Provider=Microsoft.JET.OLEDB.4.0; Data
Source=" + Application.StartupPath
+ "\\biblio.mdb");
string q = "select *
from libro where clasificacion=@CLASI";
ORDEN
= new OleDbDataAdapter(q,
CANAL);
ORDEN.SelectCommand.Parameters.Add(new OleDbParameter("@CLASI",
OleDbType.VarChar, 50));
ORDEN.SelectCommand.Parameters["@CLASI"].Value = txtClasi.Text;
//
Creando el Dataset y cargándolo
TABLA = new
DataSet();
ORDEN.Fill(TABLA, "libro");
//
Cargando el DataGridView
Grid1.DataSource = TABLA;
Grid1.DataMember = "libro";
}
private void
Busqueda_Load(object sender, EventArgs e)
{
}
}
}
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;
using System.Data.OleDb;
namespace Práctica_15
{
public partial class frmBajas : Form
{
public frmBajas()
{
InitializeComponent();
}
private void
frmBajas_Load(object sender, EventArgs e)
{
}
private void
btnBaja_Click(object sender, EventArgs e)
{
//
Objetos OleDb que se ocupan
OleDbConnection
CANAL;
OleDbCommand
ORDEN;
CANAL = new OleDbConnection("Provider=Microsoft.JET.OLEDB.4.0; Data
Source=" + Application.StartupPath
+ "\\biblio.mdb");
// Instrucción SQL para eliminar
string
q = "delete from libro where
clave=@CLAVE";
//EJECUTA
ORDEN = new OleDbCommand(q,
CANAL);
ORDEN.Parameters.Add(new OleDbParameter("@CLAVE",
OleDbType.Integer));
ORDEN.Parameters["@CLAVE"].Value = txtClave.Text;
ORDEN.Connection.Open();
ORDEN.ExecuteNonQuery();
ORDEN.Connection.Close();
// Avisando
label2.Text = "Registro eliminado";
}
}
}
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;
using System.Data.OleDb;
namespace Práctica_15
{
public partial class frmConsulta
: Form
{
public frmConsulta()
{
InitializeComponent();
}
private void
button1_Click(object sender, EventArgs e)
{
//
Declarando objetos conexión adapter y dataset
OleDbConnection CANAL;
OleDbDataAdapter ORDEN;
DataSet TABLA;
// Creando y enlazando conexión a la base de datos
// para
Access
CANAL = new OleDbConnection("Provider=Microsoft.JET.OLEDB.4.0; Data
Source=" + Application.StartupPath
+ "\\biblio.mdb");
ORDEN = new OleDbDataAdapter("Select * from libro", CANAL);
// Creando y cargando el dataset
TABLA = new
DataSet();
ORDEN.Fill(TABLA, "libro");
//
Cargando y enlazando el DataGridView
Grid1.DataSource = TABLA;
Grid1.DataMember = "libro";
}
private void
frmConsulta_Load(object sender, EventArgs e)
{
}
}
}
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 Práctica_15
{
public partial class Biblioteca :
Form
{
public Biblioteca()
{
InitializeComponent();
}
private void
btnAgregar_Click(object sender, EventArgs e)
{
Captura Sam = new Captura();
Sam.Show();
}
private void
btnEditar_Click(object sender, EventArgs e)
{
Edición Sam = new Edición();
Sam.Show();
}
private void btnLibro_Click(object sender, EventArgs
e)
{
Busqueda Sam = new
Busqueda();
Sam.Show();
}
private void
btnEliminar_Click(object sender, EventArgs e)
{
frmBajas Sam = new
frmBajas();
Sam.Show();
}
private void
Biblioteca_FormClosing(object sender, FormClosingEventArgs e)
{
}
private void
Biblioteca_Load(object sender, EventArgs e)
{
}
private void
button1_Click(object sender, EventArgs e)
{
frmConsulta Sam = new
frmConsulta();
Sam.Show();
}
}
}
No hay comentarios:
Publicar un comentario