locked
Store image or image path in sqlite. RRS feed

  • Question

  • How to store an image and image path in sqlite database in windows store apps.

    then how can I retrieve it to display that image on another page gridview background.

    I am using xaml n c# so please if possible provide me the code and tell me where to write it because  I am a beginner.

    Thanks..


    Thursday, September 26, 2013 7:56 PM

Answers

  • Hi Chirag,

    It's a frequently asked question in the forum, you could find lots of similar threads in the forum.

    And I think the first thing you need to learn is how to use sqlite, http://code.msdn.microsoft.com/windowsapps/Sqlite-For-Windows-8-Metro-2ec7a882 here is the sample for sqlite and winrt communication.

    If you wish save the path to SQLite, then that's enough, but if you want to save image into SQLite, then probably this link will helps you. https://github.com/doo/SQLite3-WinRT

    Best Regards,

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Friday, September 27, 2013 5:28 AM
    Moderator

All replies

  • Hi Chirag,

    It's a frequently asked question in the forum, you could find lots of similar threads in the forum.

    And I think the first thing you need to learn is how to use sqlite, http://code.msdn.microsoft.com/windowsapps/Sqlite-For-Windows-8-Metro-2ec7a882 here is the sample for sqlite and winrt communication.

    If you wish save the path to SQLite, then that's enough, but if you want to save image into SQLite, then probably this link will helps you. https://github.com/doo/SQLite3-WinRT

    Best Regards,

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Friday, September 27, 2013 5:28 AM
    Moderator
    • Edited by zakkar Friday, September 27, 2013 6:32 AM
    • Proposed as answer by zakkar Saturday, September 28, 2013 3:16 PM
    • Marked as answer by Jamles HezModerator Monday, September 30, 2013 1:59 AM
    • Unmarked as answer by Chirag Gohil Wednesday, October 2, 2013 11:48 AM
    Friday, September 27, 2013 6:31 AM
  • Hi Chirag Gohil

    I thing you are done download the "SQLite for Windows Runtime" Extension via Tools/Extensions, If you not using the below URL for initialize sqlite for WINRT application

    http://jesseliberty.com/2013/03/14/windows-8-storing-data-with-sqlite/

    The below example to describe store the image in sqlite

     public class Customer

    {

       [PrimaryKey, AutoIncrement]

       public int Id { get; set; } 

       public string Email { get; set; }

       public string FirstName { get; set; }

       public string LastName { get; set; }

       public byte[] Image{ get; set; }

    }

    Here the Image column is array of bytes for storing the customer image.

     

                                                    //// Get the stream from image file and convert to array byte for storage to sqlite

                        IInputStream inputStream = thumbnailImage.GetInputStreamAt(0);

                        DataReader dataReader = new DataReader(inputStream);

                        uint streamSize = (uint)thumbnailImage.Size;

                        await dataReader.LoadAsync(streamSize);

                        byte[] imagebuffer = new byte[streamSize];

                        dataReader.ReadBytes(imagebuffer);

     

     using ( var db = new SQLite.SQLiteConnection( _dbPath ) )

       {

          db.CreateTable<Customer>();

     

          //Note: This is a simplistic initialization scenario

          if ( db.ExecuteScalar<int>(

                 "select count(1) from Customer" ) == 0 )

          {

     

             db.RunInTransaction( () =>

             {

                db.Insert( new Customer()

                      {

                   FirstName = "Jon",

                   LastName = "Galloway”,

                    Email   = “Galloway@gmail.com”,

                   Image    = imagebuffer

     

     

                                        } );

             } );

          }

          else

          {

             ////

          }

       }



    Monday, September 30, 2013 12:41 PM