使用下面的代码,我该如何在SQLiteConnetion对象中设置代码?C# - 如何从一个路径复制SQLite数据库并将其粘贴到另一个路径?
public SQLiteConnection dbConnection = new SQLiteConnection();
string fileName = "test.s3db";
string sourcePath = @"E:\File\DMS\DAL\Model";
string targetPath = @"C:\ProgramData\CompanyName\appName";
string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
string destFile = System.IO.Path.Combine(targetPath, fileName);
if (!System.IO.Directory.Exists(targetPath))
{
System.IO.Directory.CreateDirectory(targetPath);
}
System.IO.File.Copy(sourceFile, destFile, true);
if (System.IO.Directory.Exists(sourcePath))
{
string[] files = System.IO.Directory.GetFiles(sourcePath);
}
我想,如果路径不存在自动创建一个数据库路径。
dbConnection = ??
你能否澄清你是什么_表示“我怎么可以设置SQLiteConnetion对象的代码” _?你的代码似乎是正确的。你能提供一个不工作的代码片段吗? –
@ botond.botos嗨其实我正面临的问题是,请看看这个网址:http://stackoverflow.com/questions/40689467/where-to-store-my-windows-applications-data。然后,我想创建一个默认路径,当在任何本地计算机上安装我的应用程序,同时在wpf中创建安装文件时c# – lashja
有一种不同的方法描述在http://stackoverflow.com/questions/15292880/create-sqlite-database-and-table 。它不会复制数据库文件,而是在运行时创建它。 –