class ConsultasSQL
{
private SqlConnection conexion = new SqlConnection("Data source = JoseM;
Initial catalog = Trabajo_Dise; Integrated security = true ");
private DataSet ds;
public DataTable MostrarDatos()
{
[Link]();
SqlCommand cmd = new SqlCommand("select * from tb_cliente",
conexion);
SqlDataAdapter ad = new SqlDataAdapter(cmd);
ds = new DataSet();
[Link](ds, "tabla");
[Link]();
return [Link]["tabla"];
}
public DataTable Buscar(string nombre)
{
[Link]();
SqlCommand cmd = new SqlCommand([Link]("select * from
tb_cliente where nombre like '%(0)%'",nombre), conexion);
SqlDataAdapter ad = new SqlDataAdapter(cmd);
ds = new DataSet();
[Link](ds, "tabla");
[Link]();
return [Link]["tabla"];
}
public bool insertar(string cod_cliente, string nombre, string direccion,
string edad, string telefono)
{
[Link]();
SqlCommand cmd = new SqlCommand([Link]("insert into tb_cliente
values ({0}, '{1}','{2}',{3},'{4}')", new string[] { cod_cliente, nombre,
direccion, edad, telefono }),conexion);
int filasafectadas = [Link]();
[Link]();
if (filasafectadas > 0) return true;
else return false;
}
}
public bool eliminar (string cod_cliente)
{
[Link]();
SqlCommand cmd = new SqlCommand([Link]("Delete from tb_cliente
where cod_cliente = {0}", cod_cliente), conexion);
int filasafectadas = [Link]();
[Link]();
if (filasafectadas > 0) return true;
else return false;
}
public bool Actualizar(string cod_cliente, string nombre, string
direccion, string edad, string telefono)
{
[Link]();
SqlCommand cmd = new SqlCommand([Link]("update tb_cliente set
nombre = '{0}', direccion = '{1}',edad = '{2}',telefono ='{3}' where cod_cliente
= {4}", new string[] { nombre, direccion, edad, telefono, cod_cliente }),
conexion);
int filasafectadas = [Link]();
[Link]();
if (filasafectadas > 0) return true;
else return false;
BOTONES:
Abajo de initializecomponent : ConsultasSQL sql = new ConsultasSQL();
[Link] = [Link]();
if ([Link]([Link], [Link], [Link],
[Link], [Link]))
{
[Link]("Datos insertados");
[Link] = [Link]();
}
else [Link]("No se han podido insertar los datos");
}
private void button2_Click(object sender, EventArgs e)
{
if([Link]([Link]))
{
[Link]("Datos eliminados");
[Link] = [Link]();
}
else [Link]("No se han podido eliminar los datos");
}
private void button3_Click(object sender, EventArgs e)
{
if([Link]([Link], [Link], [Link],
[Link], [Link]))
{
[Link]("Datos Actualizados");
[Link] = [Link]();
}
else [Link]("No se han podido actualizar los datos");
}