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
C# 项目赢得';t加载到所选数据库,在调试文件夹中复制_C#_Sqlite_Csv - Fatal编程技术网

C# 项目赢得';t加载到所选数据库,在调试文件夹中复制

C# 项目赢得';t加载到所选数据库,在调试文件夹中复制,c#,sqlite,csv,C#,Sqlite,Csv,这个程序应该获取一个csv文件,并将其加载到sqlite数据库中,用户指定了该数据库的路径。它不会尝试将值加载到所选数据库,而是在调试文件夹中创建数据库的副本,然后抛出错误,因为新数据库中不存在该表。我找不到它决定在哪里创建新文件而不是使用现有文件 using (System.Data.SQLite.SQLiteConnection conn = new System.Data.SQLite.SQLiteConnection("data source=" + db3FilePath + "; S

这个程序应该获取一个csv文件,并将其加载到sqlite数据库中,用户指定了该数据库的路径。它不会尝试将值加载到所选数据库,而是在调试文件夹中创建数据库的副本,然后抛出错误,因为新数据库中不存在该表。我找不到它决定在哪里创建新文件而不是使用现有文件

using (System.Data.SQLite.SQLiteConnection conn = new System.Data.SQLite.SQLiteConnection("data source=" + db3FilePath + "; Synchronous=Off"))
{
    using (System.Data.SQLite.SQLiteCommand cmd = new System.Data.SQLite.SQLiteCommand(conn))
    {
        conn.Open();

        foreach (KeyValuePair<string, CSVRecord> kvp in csvDictionary.Skip(1))
        {
            //checks for duplicate records
            cmd.CommandText = "SELECT COUNT(*) FROM Accounts WHERE SDM_ACCT='" + kvp.Value.sdmacct + "'";
            int count = Convert.ToInt32(cmd.ExecuteScalar());

            if (count < 1)
            {
                WritetoDatabase.WritetoAccountsTable(kvp.Value.description, kvp.Value.priority, db3FilePath);
                WritetoDatabase.WritetoDirectoryTable(kvp.Value.number, kvp.Value.active, db3FilePath);

                recordCount++;
                //updates the progress bar and text field showing %
                int progress = y++ * 100 / (csvDictionary.Keys.Count -1);
                progressBar1.Invoke((MethodInvoker)(() => progressBar1.Value = progress));
                progressBar1.Invoke((MethodInvoker)(() => progressBar1.Update()));
                lblStatus.Invoke((MethodInvoker)(() => lblStatus.Text = "Writing records to database: " + progress.ToString() + "% Complete"));
                lblStatus.Invoke((MethodInvoker)(() => lblStatus.Update()));
            }
            else
            {
                WritetoDatabase.WritetoDirectoryTable(kvp.Value.number, kvp.Value.active, db3FilePath);
                y++;
            }
        }
        conn.Close();
    }
}

我已经改变了我所能想到的一切,试图找出问题的根源。也许你会看到一些我看不到的东西。

这是我见过的打破程序的最愚蠢的事情之一。使用(System.Data.SQLite.SQLiteConnection conn=new System.Data.SQLite.SQLiteConnection(“Data source=“+filePath+”;“Synchronous=Off”)的连接字符串具有“Data source”。如果它不是大写的“数据源”,它将无法识别它并转到默认设置。

Visual Studio解决方案中是否包含数据库文件?db3FilePath的值是多少?不是。其想法是,数据库将在服务器上运行,程序将使用
OpenFileDialog()
将所选路径保存到db3FilePath,而
db3FilePath的值是多少?在本例中为“C:\Users\bminster\Downloads\Directory.db”
public static int WritetoAccountsTable(string Comment, int PriorityInt, string filePath)
        {
            using (System.Data.SQLite.SQLiteConnection conn = new System.Data.SQLite.SQLiteConnection("data source=" + filePath + "; Synchronous=Off"))
            {
                using (System.Data.SQLite.SQLiteCommand cmd = new System.Data.SQLite.SQLiteCommand(conn))
                {
                    conn.Open();
                    cmd.CommandText = @"INSERT INTO Accounts(Description,Priority) 
                                                        values(@Comment,@PriorityInt)";
                    cmd.Parameters.AddWithValue("@Comment", Comment);
                    cmd.Parameters.AddWithValue("@PriorityInt", PriorityInt);
                    return cmd.ExecuteNonQuery();
                }
            }
        }