Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在UWP中写入只读sqlite文件_Sqlite_Uwp - Fatal编程技术网

如何在UWP中写入只读sqlite文件

如何在UWP中写入只读sqlite文件,sqlite,uwp,Sqlite,Uwp,所以我是UWP新手,在完成连接sqlite之后,我稍微修改了一下代码以尝试新的东西。我没有在本地文件夹中创建并保存sqlite文件,而是将文件目录更改为installed location,创建了一个文件夹“data”,并在其中添加sqlite文件。在这一点上,你可以找出我遇到了什么问题。我只能读取/选择表,但不能写入/插入、删除和更新数据库中的记录。我有点期待这个问题,我知道原因。我想知道的是: 我可以将安装位置中的只读sqlite文件更改为读写吗?如果你能告诉我怎么走 将数据库文件保存在安

所以我是UWP新手,在完成连接sqlite之后,我稍微修改了一下代码以尝试新的东西。我没有在本地文件夹中创建并保存sqlite文件,而是将文件目录更改为installed location,创建了一个文件夹“data”,并在其中添加sqlite文件。在这一点上,你可以找出我遇到了什么问题。我只能读取/选择表,但不能写入/插入、删除和更新数据库中的记录。我有点期待这个问题,我知道原因。我想知道的是:

  • 我可以将安装位置中的只读sqlite文件更改为读写吗?如果你能告诉我怎么走
  • 将数据库文件保存在安装位置是可行的还是好主意?或者最好将其保存在本地文件夹中
这是我的代码:

对于mainpage.xaml

<GridView x:Name="gridView" BorderBrush="Blue" BorderThickness="2" HorizontalAlignment="Left" Margin="34,401,0,0" VerticalAlignment="Top" Height="287" Width="1219">
        <GridView.ItemTemplate>
            <DataTemplate x:DataType="data:Test" x:Name="templateGrid">
                <StackPanel x:Name="stackPanel"  Orientation="Vertical" HorizontalAlignment="Center">
                    <StackPanel x:Name="stack2" Margin="20,20,0,0">
                        <TextBlock FontSize="18" Text="{x:Bind ID}" HorizontalAlignment="Center"></TextBlock>
                        <TextBlock FontSize="10" Text="{x:Bind Name}" HorizontalAlignment="Center"></TextBlock>
                    </StackPanel>
                </StackPanel>
            </DataTemplate>
        </GridView.ItemTemplate>
    </GridView>
    <TextBlock x:Name="textBlock" HorizontalAlignment="Left" Margin="10,112,0,0" TextWrapping="Wrap" Text="Name" FontSize="25" VerticalAlignment="Top"/>
    <TextBox x:Name="textBox" HorizontalAlignment="Left" Margin="132,112,0,0" FontSize="25" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="328"/>
    <Button x:Name="button2" Content="Add" Click="button2_Click" HorizontalAlignment="Left" Margin="516,125,0,0" VerticalAlignment="Top"/>
我收到的错误是:

An exception of type 'SQLite.Net.SQLiteException' occurred in SQLite.Net.dll but was not handled in user code

Additional information: ReadOnly

提前感谢。

应用程序的安装目录是只读位置(请参阅)。它用于应用程序代码和资产


如果您需要对数据库进行写访问,则无法将其放在应用程序的安装目录中。

谢谢您的回答。但是我已经知道了,我只是想知道对于数据库文件这个问题是否有解决的方法。@Dant:安全不是通过锁门来实现的,而是在门垫下留下一把钥匙。如果需要读/写数据库,请将其存储在具有读/写访问权限的位置。我不知道这算不算把戏。
create table Test
(
ID integer primary key autoincrement,
Name nvarchar(25)
);

insert into Test (Name) values ("Test value 1")
An exception of type 'SQLite.Net.SQLiteException' occurred in SQLite.Net.dll but was not handled in user code

Additional information: ReadOnly