无法在WPF项目中写入SQLite数据库

时间:2017-09-30 01:26:16

标签: c# sql database wpf sqlite

有其中一个撕裂你的头发晚上。

我正在将WPF项目从使用访问和OleDBConnection移植到使用SQLite和SQLiteConnection。我的应用程序在加载时从项目中读取,然后在一些表单输入后写入它。

阅读效果很好,使用以下代码:

private void InitialiseDB()
    {
                   connString = "data source = PortalDB.db";

        conn = new SQLiteConnection(connString);

                            SQLiteCommand AttendeeCmd = new SQLiteCommand("SELECT * FROM AttendeeNames", conn);
                            SQLiteCommand SignInOutsCmd = new SQLiteCommand("SELECT SignTime, UserID, SignType FROM SignInOuts", conn);

            conn.Open();

            SQLiteDataAdapter AttendeeAdapter = new SQLiteDataAdapter(AttendeeCmd);
            SQLiteDataAdapter SignInOutsAdapter = new SQLiteDataAdapter(SignInOutsCmd);


            //Clear current datatables
            AttendeeNamesTable.Clear();
            SignInOutsTable.Clear();
            //Fill data tables from adapters
            AttendeeAdapter.Fill(AttendeeNamesTable);
            SignInOutsAdapter.Fill(SignInOutsTable);
            conn.Close();

    }

但是对于我的生活,我无法让写作工作,它不会抛出任何错误或异常,它只是不写入数据库。该代码看起来像这样,数据从刚刚被传递到本地DataTable:

private void SyncUpDB(int SignUserId, string SignType, DateTime SignTime)
       {

        //...Open the connection...
         conn.Open();
         //..Make SQL query by declaring fields to write to (not SignID) and where to get the data from. Strings need single quote, numbers do not.
         String SyncUpDBQuery = "INSERT INTO SignInOuts (SignTime,UserID,SignType) VALUES('" + SignTime + "', " + SignUserId + ", '" + SignType + "')";
         //...Make new database command from query
         SQLiteCommand SyncUpDBCommand = new SQLiteCommand(SyncUpDBQuery, conn);
         //...And execute on database
         SyncUpDBCommand.ExecuteNonQuery();

    }

正如我所说,这曾经与Access完美配合,只是不会与SQLite玩球...任何想法?

0 个答案:

没有答案