Informatica
1. Crea una base de Datos en Access
2. Crea un Nuevo proyecto en C#
3. Agrega una nueva clase llamada Database y a continuaciónescribe el siguiente código:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;
namespace bd_access2
{
classDatabase
{
private string StrConexion;
private OleDbConnection Conexion;
private OleDbDataAdapter Adapter;
private DataSet miDataSet = new DataSet();
public void IniciarConexion(string DataBase)
{//Creo la cadena de conexion para Office 2007
StrConexion = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source = " + DataBase;
//Objeto conexion
Conexion = new OleDbConnection(StrConexion);
}public int ejecutar_sql(string sql)
{
//inserto en la BD
int i = 0;
try
{
Conexion.Open();
OleDbCommand cmd = new OleDbCommand(sql, Conexion);
i = cmd.ExecuteNonQuery();
}
catch
{
i = -1;
}return i;
}
public DataTable consultar(string sql, string tabla)
{
Adapter = new OleDbDataAdapter(sql, Conexion);
//Creo el DataTable
DataTable dt = new DataTable();
//Relleno el adaptadorcon los datos en memoria
Adapter.Fill(dt);
return dt;
}
}
}
4. Crea una nueva clase llamada Alumnos y escribe el siguiente código:
using System;
using System.Collections.Generic;
usingSystem.Linq;
using System.Text;
namespace bd_access2
{
class Alumnos
{
public string ncuenta;
public string nombre;
public string apellidop;
public string apellidom;
public int edad;
public intsemestre;
public Alumnos()
{
}
public Alumnos(string ncuenta, string nombre, string apellidop, string apellidom, int edad, int
semestre)
{
this.ncuenta = ncuenta;
this.nombre = nombre;this.apellidop = apellidop;
this.apellidom = apellidom;
this.edad = edad;
this.semestre = semestre;
}
}
}
5. Edita el formulario agregando los siguientes componentes:
6. Edita la propiedad...
Regístrate para leer el documento completo.