locked
How can i create SQLite DB? RRS feed

  • Question

  • User397929 posted

    I want create SQLite DB when application is opened first time or when DB does not exist. How can i do that?

    ```
    string fileName = "recommendList.db";
        string folderPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
        public static string completePath;
    
        public App()
        {
            InitializeComponent();
    
            //MainPage = new MainPage();
            MainPage = new masterDetailPage();
    
            completePath = Path.Combine(folderPath, fileName);
        }
    
        protected override void OnStart()
        {
            using (var db = new SQLiteConnection(completePath))
            {
                if (!System.IO.File.Exists(completePath))
                {
    
                }
    
                else
                {
    
                }
            }
        }
    

    ```

    Friday, November 27, 2020 2:50 AM

Answers

  • User371688 posted

    Do you mean the SQLite DB in android platform?

    Then you can check the official document here: https://docs.microsoft.com/en-us/xamarin/android/data-cloud/data-access/using-sqlite-orm

    And there are samples about this at the bottom of above page. You can check them here: https://docs.microsoft.com/en-us/xamarin/android/data-cloud/data-access/using-sqlite-orm#related-links

    Hope it can help you.


    Xamarin forums are migrating to a new home on Microsoft Q&A! We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A! For more information, please refer to this sticky post.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, November 27, 2020 5:05 AM

All replies

  • User371688 posted

    Do you mean the SQLite DB in android platform?

    Then you can check the official document here: https://docs.microsoft.com/en-us/xamarin/android/data-cloud/data-access/using-sqlite-orm

    And there are samples about this at the bottom of above page. You can check them here: https://docs.microsoft.com/en-us/xamarin/android/data-cloud/data-access/using-sqlite-orm#related-links

    Hope it can help you.


    Xamarin forums are migrating to a new home on Microsoft Q&A! We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A! For more information, please refer to this sticky post.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, November 27, 2020 5:05 AM
  • User397929 posted

    @jezh Thank you! But i use Xamarin.Forms

    Friday, November 27, 2020 7:59 AM
  • User371688 posted

    Do you want to create SQLite DB in android device in xamarin forms app?

    Then you can use DependencyService to achieve this. The DependencyService class is a service locator that enables Xamarin.Forms applications to invoke native platform functionality from shared code.

    For more details, you can check above document.

    If you have any problem in achieving above function, feel free to let me know. I am willing to help you. :)

    Friday, November 27, 2020 8:04 AM
  • User397929 posted

    @jezh Thank you for comment! I read https://docs.microsoft.com/en-us/xamarin/android/data-cloud/data-access/using-sqlite-orm really really slowly again. And i found solution.

    Sunday, November 29, 2020 11:26 PM