Visual Studio 2008 – Windows Embedded con SQLite

by | Jun 5, 2019

Realice la configuración en una maquina virtual con Windows XP creada con VirtualBox (https://www.virtualbox.org/)

En la maquina virtual instalé:
1.- Visual Studio 2005 o 2008
2.- Windows Mobile 6 Professional SDK Refresh (https://www.microsoft.com/en-us/download/details.aspx?id=6135)
3.- Windows Mobile 6.5.3 Professional DTK (https://www.microsoft.com/en-us/download/details.aspx?id=5389)
4.- SQLite 1.0.66.0 (https://sourceforge.net/projects/sqlite-dotnet2/files/SQLite%20for%20ADO.NET%202.0/1.0.66.0/)
5.- Microsoft ActiveSync version 4.5 (https://www.microsoft.com/es-cl/download/details.aspx?id=15)

Crear un nuevo proyecto en visual studio 2005 o 2008 y seleccionar “Visual C#” -> “Smart Device” -> “Smart Device Project”:

Luego referenciar la librería de SQLite, boton derecho sobre el proyecto -> “Add Reference”, en la viñeta “.NET” hacer doble click en “System.Data.SQLite”:

Crear una base de datos SQLite con “sqliteadmin” (https://sqliteadmin.orbmu2k.de/), acá dejo la base que utilice para esta prueba bajar aquí:

Agrear la base de datos al proyecto.

En el formulario agregar un “button” y un “label” y en el código escribir lo siguiente:

using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SQLite;
namespace Prueba2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            string query = "SELECT * FROM test";
            string conString = "Data Source = \Program Files\Data\test.s3db";
            SQLiteConnection con = new SQLiteConnection(conString);
            SQLiteCommand cmd = new SQLiteCommand(query, con);
            con.Open();
            try
            {
                SQLiteDataReader rdr = cmd.ExecuteReader();
                try
                {
                    while (rdr.Read())
                    {
                        this.label1.Text += string.Format("\r\nID:{0} Nombre: {1}", rdr[0].ToString(), rdr[1].ToString());
                    }
                }catch(Exception ex){
                    MessageBox.Show(ex.Message);
                }
            }catch(Exception exc){
                MessageBox.Show(exc.Message);
            }
        }
    }
}