Windows phone 7 如何将现有数据库文件添加到我的windows phone 7应用程序中并从中读取数据?

Windows phone 7 如何将现有数据库文件添加到我的windows phone 7应用程序中并从中读取数据?,windows-phone-7,Windows Phone 7,如何添加现有的数据库文件(例如:-x.sdf)并将数据库文件中的数据转储到手机的本地数据库中 我希望在最终用户安装应用程序本身时执行此操作。检查文章的“应用程序部署”部分;在这里,您将看到如何在应用程序中部署只读数据库,以及在部署后如何使其可写 检查文章的“应用程序部署”部分;在这里,您将看到如何在应用程序中部署只读数据库,以及在部署后如何使其可写 如果需要预加载数据库,则可以在应用程序中添加sqlCe数据库,并用种子数据填充数据库。 然后,在调用DBContext的构造函数时,可以将DB文件复

如何添加现有的数据库文件(例如:-x.sdf)并将数据库文件中的数据转储到手机的本地数据库中


我希望在最终用户安装应用程序本身时执行此操作。

检查文章的“应用程序部署”部分;在这里,您将看到如何在应用程序中部署只读数据库,以及在部署后如何使其可写

检查文章的“应用程序部署”部分;在这里,您将看到如何在应用程序中部署只读数据库,以及在部署后如何使其可写

如果需要预加载数据库,则可以在应用程序中添加sqlCe数据库,并用种子数据填充数据库。 然后,在调用DBContext的构造函数时,可以将DB文件复制到ISO存储区

public Moviadb1DataContext (string connectionString) : base(connectionString)
    {
        IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication();

        if (!iso.FileExists("Moviadb1.sdf"))
        {
            MoveReferenceDatabase();
        }

        if (!DatabaseExists())
            CreateDatabase();
    }

    public static void MoveReferenceDatabase()
    {
        // Obtain the virtual store for the application.
        IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication();

        // Create a stream for the file in the installation folder.
        using (Stream input = Application.GetResourceStream(new Uri("Moviadb1.sdf", UriKind.Relative)).Stream)
        {
            // Create a stream for the new file in isolated storage.

            using (IsolatedStorageFileStream output = iso.CreateFile("Moviadb1.sdf"))
            {
                // Initialize the buffer.
                byte[] readBuffer = new byte[4096];
                int bytesRead = -1;

                // Copy the file from the installation folder to isolated storage. 
                while ((bytesRead = input.Read(readBuffer, 0, readBuffer.Length)) > 0)
                {
                    output.Write(readBuffer, 0, bytesRead);
                }
            }
        }
    }

如果需要预加载数据库,则可以在应用程序中添加sqlCe数据库,并用种子数据填充数据库。 然后,在调用DBContext的构造函数时,可以将DB文件复制到ISO存储区

public Moviadb1DataContext (string connectionString) : base(connectionString)
    {
        IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication();

        if (!iso.FileExists("Moviadb1.sdf"))
        {
            MoveReferenceDatabase();
        }

        if (!DatabaseExists())
            CreateDatabase();
    }

    public static void MoveReferenceDatabase()
    {
        // Obtain the virtual store for the application.
        IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication();

        // Create a stream for the file in the installation folder.
        using (Stream input = Application.GetResourceStream(new Uri("Moviadb1.sdf", UriKind.Relative)).Stream)
        {
            // Create a stream for the new file in isolated storage.

            using (IsolatedStorageFileStream output = iso.CreateFile("Moviadb1.sdf"))
            {
                // Initialize the buffer.
                byte[] readBuffer = new byte[4096];
                int bytesRead = -1;

                // Copy the file from the installation folder to isolated storage. 
                while ((bytesRead = input.Read(readBuffer, 0, readBuffer.Length)) > 0)
                {
                    output.Write(readBuffer, 0, bytesRead);
                }
            }
        }
    }

您是需要更新数据库还是数据为只读?我想对数据库进行读/写操作(对其执行操作)。您是需要更新数据库还是数据为只读?我想对数据库进行读/写操作(对其执行操作)