0

I am using xamarin forms and I am having trouble access a table in the database of sqlite which already exists.

Exception is:

Unhandled Exception:

SQLite.SQLiteException: no such table: Boms

public StockDatabase()
{

     var path = Path.Combine(System.Environment.
     GetFolderPath(System.Environment.
     SpecialFolder.Personal), "FuelStockApp2.db3");

     Console.Write("OPening Database dbPath" + path);
     database = new SQLiteAsyncConnection(path);
}

I use sql browser to create my table as per below.This is the call i am using to make it out to the table, using dapper.

public Task<List<Boms>> GetBomsFroMSQlLite()          
{

        return database.Table<Boms>().ToListAsync();
}

enter image description here

namespace StockAppDal.Models
{
   public class Boms
   {
       public enum BomStatus
       {
        InAcitve = 0,
        Listed =1,
        Scanned = 2,
        Completed = 3

    }

    public BomStatus Status { get; set; }
    public long BomId { get; set; }
    public long BOMLineID { get; set; }
    public long StockItemID { get; set; }
    public string BOMLineTypeID { get; set; }
    public decimal? Quantity { get; set; }
    public long UnitID { get; set; }
    public decimal? MultipleOfBaseUnit { get; set; }
    public string Code { get; set; }
    public string Name { get; set; }
    public string Barcode { get; set; }
    public long ProductGroupID { get; set; }
    public string ProductGroupCode { get; set; }
    public bool Scanned { get; set; }      
    public List<Warehouse> Warehouses { get; set; }
    public List<BomDetail> Lines { get; set; }

    public override string ToString()
    {
        return Code;
    }
  }
}

Is there anything I must to mark my class as being accessible here I am using Dapper as well.

m

Note 2: Why in this example its showing that one can access the database in such this way that I am doing

https://github.com/xamarin/xamarin-forms-samples/blob/master/Todo/Todo/App.cs

Cœur
  • 37,241
  • 25
  • 195
  • 267
c-sharp-and-swiftui-devni
  • 3,743
  • 4
  • 39
  • 100
  • you cannot open an asset using a file path, and assets are also not writable at run time. You will need to copy your seed db from Assets to SpecialFolder.Personal when your app first runs, then open the db from there – Jason May 18 '19 at 18:35
  • @Jason can you provide an example or documentation. – c-sharp-and-swiftui-devni May 18 '19 at 18:37
  • @Jason I cannot access the andriod command in my forms app project how do i copy the db. – c-sharp-and-swiftui-devni May 18 '19 at 18:42
  • copying the db from Assets has to be done in the Android project. Once it has been copied you should be able to open it using SQLiteAsyncConnection from the Forms project – Jason May 18 '19 at 19:39

0 Answers0