Herramientas Informaticas

Categoría: VISUAL STUDIO 2012

CLASE PARA MOSTRAR USUARIO EN DATAGRID

using System;

using System.Collections.Generic;

using System.Data;

using System.Data.SQLite;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

 

 

namespace Prueba.Clases

{

    class usuarios

    {

 

        public void mostrar(DataGridView dv)

        {

            

            conexion con = new conexion();

            

 

            string sql ="SELECT USUARIO, CONTRA as contraseña FROM USUARIOS";

            SQLiteDataAdapter db = new SQLiteDataAdapter(sql, con.sqlCon);

 

            DataSet ds = new DataSet();

            ds.Reset();

 

            DataTable dt = new DataTable();

            db.Fill(ds);

            dt = ds.Tables[0];

 

            dv.DataSource = dt;

            

            // CERRAMOS LA CONEXION

            con.cerrarConexion();

        }

    }

}

CONEXION CON VISUAL STUDIO 2012 C# CON SQLITE

/*JULIO CESAR LEYVA RODRIGUEZ 

 * 15 DE JUNIO DE 2013

 */

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Data.SQLite;

 

 

namespace Prueba

{

    

    //HACEMOS LA CLASE PARA LA CONEXION

    class conexion

    {

        

        /* HACEMOS LAS VARIABLES DE CONEXION, SE NECESITARAN INSTALAR Y AGREGAR LAS LIBRERIAS DE

         * SQLITE http://www.sqlite.org/download.html

         */

        public SQLiteConnection sqlCon;

        public SQLiteCommand sqlCmd;

 

        public conexion()

        {

            //ESTABLECEMOS LA DIRECCION DEL ARCHIVO DE LA BASE DE DATOS Y ABRIMOS CONEXION

            sqlCon = new SQLiteConnection("Data Source=|DataDirectory|compras.s3db;");

            sqlCon.Open();

        }

        

        //FUNCION PARA CERRAR LA CONEXION

        public void cerrarConexion()

        {

            sqlCon.Close();

        }

 

        //EJECUTA LA CONSULTA QUE SE LE MANDA COMO PARAMETRO

        public void ejecutar(string sql)

        {

            sqlCmd = new SQLiteCommand(sql, sqlCon);

            sqlCmd.ExecuteNonQuery();

        }

 

       

        //FUNCION DE PRUEBA QUE SIRVE DE ACCESO A UN USUARIO

        public bool acceso(string usuario, string cont)

        {

            string  sql = "select * from usuarios where usuario='" + usuario + "' and contra='" + cont + "'";

            sqlCmd = new SQLiteCommand(sql, sqlCon);

            sqlCmd.ExecuteNonQuery();

            bool chekar  = sqlCmd.ExecuteReader().HasRows;

            return chekar;

        }

 

    }

 

}

Creado con WordPress & Tema de Anders Norén