Search code examples
c#sqlitesmart-device

Unable retrieve records from SQLite database for smart device application


I am using SQLite.NET with C#[ visual studio 2008] and added the 'System.Data.SQLite.dll' as reference. The following code works with Windows Application for fetching data from my database file into a datagrid.

    private void SetConnection()
    {
        sql_con = new SQLiteConnection("Data Source=emp.db;Version=3;");
    }

    public DataTable LoadData()
    {
        SetConnection();
        sql_con.Open();
        sql_cmd = sql_con.CreateCommand();
        string CommandText = "select * from employeedetails";
        transaction=sql_con.BeginTransaction();
        DA = new SQLiteDataAdapter(CommandText, sql_con);
        DS.Reset();
        DA.Fill(DS);
        DT = DS.Tables[0];
        transaction.Commit();
        sql_con.Close();
        return DT;
    }

Invoking in:

    private void Form1_Load(object sender, EventArgs e)
    {
        EmpTable obj = new EmpTable();     
        this.dataGridView1.DataSource = obj.LoadData();
    }

The same code not working with C# 'Smart Device Application'. It shows an exception: no such table 'employeedetails'.

For Smart Device Application I have added the System.Data.SQLite.dll from "SQLite/CompactFramework" folder.

Please help me to resolve this.

Thanks in advance.


Solution

  • Thank You Guys,

    I've resolved the Problem. As 'siyw' said, the problem was the application could not find the "db file".

    For windows application,

    The db file has to be located in debug folder where the .exe file is generated. So that, no need to specify the path of the DB file.

    For Smart Device Application,

    The DB file will be generated in the root folder of the device. If we bind the db file with exe means, it wont find it and it will create a new database in root folder.

    To avoid that, while crating CAB file we have to create custom folder [ ex. DBfolder ] and put the db file in the folder. Set the path in the connection String as,

    sql_con = new SQLiteConnection("Data Source=DBfolder/emp.db;Version=3;");
    

    Now, the db is found by the Application.