Last Updated
Viewed 06 Times
           

i'm programing with Xamarin,and i need a way to put my database in /data/user/0/App1.App1/files/dvp.db
but i don't know how to find this path and i didn't find any way to do it

On my Xamarin android application i create db path using the "System.Environment.SpecialFolder.Personal". I have an existing sqlite database. Where in the project and with what properties must i include the database to be used in the peronal folder?

Similar Question 2 : C# Xamarin SQLite Database Error

I still getting the same error on every device I have while using SQLite: "System.DllNotFoundException: /system/lib/libsqlite.so occurred"

It always happens on this line:

var r = SQLite3.Open (databasePathAsBytes, out handle, (int) openFlags, IntPtr.Zero);

What can I do?

EDIT: Is this function correct used???:

public bool CreateDatabase()
{
    try
    {
        using (var connection = new SQLiteConnection(System.IO.Path.Combine(folder, "CryptoSimulator.db")))
        {
            connection.CreateTable<Portfolio>();
            connection.CreateTable<Wallet>();
            connection.CreateTable<Assignments>();
            return true;
        }
    }
    catch(SQLiteException ex)
    {
        Log.Info("SQLiteEx", ex.Message);
        return false;
    }
}

I am unable to drop tables completely from sqLite database in XAMARIN using command db.DropTable<tablename>. It gets dropped at first but appears again every time I restart the application. Also I have multiple tables with the same name and I need to drop them all. What should I do?

I am developing an android application in Visual Studio using XAMARIN and C#.

Unfortunately I created many tables with the same name. Now I need to drop them.

I am using following code to create tables and database:-

namespace Test
{
[Table("OrderDetails")]
public class OrderDetails
{
    [PrimaryKey, AutoIncrement, Column("_id")]
    public int Id { get; set; }
    [MaxLength(50)]
    public string payeename { get; set; }
    [MaxLength(100)]
    public string commodity { get; set; }

    public int give { get; set; }

    public int take { get; set; }
    public DateTime date { get; set; }
}

[Activity(Label = "Test", MainLauncher = true)]
public class MainActivity : Activity
{

    [Table("Items")]
    public class PayeeMaster
    {
        [PrimaryKey, AutoIncrement, Column("_id")]
        public int Id { get; set; }
        [MaxLength(8)]
        public string FirstName { get; set; }
        [MaxLength(8)]
        public string LastName { get; set; }
    }
    SQLiteConnection db;

    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);

        // Set our view from the "main" layout resource
        SetContentView(Resource.Layout.Main);

        CreateDatabase();



    }


   public bool ifExists_Table(string tablename)
    {



        SQLiteCommand command = db.CreateCommand("SELECT COUNT(1) FROM SQLITE_MASTER WHERE TYPE = @TYPE AND NAME = @NAME");
        command.Bind("@TYPE", "table");
        command.Bind("@NAME", tablename);

        int result = command.ExecuteQuery<int>();
        return (result > 0);


    }

  public void CreateDatabase() {
     try
     {  
            string dbPath = Path.Combine(

System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal),
            "Master.db3");

            db = new SQLiteConnection(dbPath);

        }
        catch (IOException ex)
        {
            var reason = string.Format("The database failed to create - 
     reason {0}", ex.Message);

        }



            if (!ifExists_Table("PayeeMaster"))
            {

                db.CreateTable<PayeeMaster>();
            }

            else
            {
                var count = db.Table<PayeeMaster>().Count();

            }



        if (!ifExists_Table("OrderDetails"))
            {

                db.CreateTable<OrderDetails>();
            }

            else {
                var count = db.Table<OrderDetails>().Count();
            }


     }
 }

Similar Question 4 (3 solutions) : how to use persistent database in android application

Similar Question 6 (1 solutions) : Can't Create SQLite Database in Xamarin.Android

cc