SQLite关键字' OR'附近的语法不正确

时间:2016-11-14 15:32:31

标签: c# sqlite

我正在尝试使用以下查询插入或替换到SQLite数据库中:

INSERT OR REPLACE INTO VersionNumbers
(VersionNumberID,
ENVID,
EnvShortName,
VersionNumber,
BuildNumber,
SourceGetVersion,
DeploymentDate,
CreatedDateTime,
ModifiedDateTime,
Deleted,
LastGetFromServerDateTime)
Values
('da8e3589-4511-4300-a081-ff57998be949',
'd2303c80-ce8e-4a66-98ca-009b5073e967',
'Environment A',
'16.3.1610.2708', 
'BuildNumber_20161027.2', 
'C99633', 
'2016-10-31', 
'10/10/2016 12:35:41', 
'14/11/2016 10:55:15', 
'0',
'14/11/2016 15:21:05')

我使用DB Browser for SQLite测试了这个并直接在数据库上执行SQL,这一切都很好,但如果我通过C#传递相同的查询,我会得到错误"错误的语法附近关键字'或'。"

C#

dbConnection.ConnectionString = DataDbConnString;
dbConnection.Open();
foreach (DataRow dataRow in dataTableVersion.Rows)
{
    try
    {
        var QueryUpdateOrInsert = @"INSERT OR REPLACE INTO VersionNumbers
                                      (VersionNumberID,
                                      ENVID,
                                      EnvShortName,
                                      VersionNumber,
                                      BuildNumber,
                                      SourceGetVersion,
                                      DeploymentDate,
                                      CreatedDateTime,
                                      ModifiedDateTime,
                                      Deleted,
                                      LastGetFromServerDateTime) Values (" +
                                      "'" + dataRow["VersionNumberID"] + "'," +
                                      "'" + dataRow["ENVID"] + "'," +
                                      "'" + dataRow["ENVShortName"] + "'," +
                                      "'" + dataRow["CurrentVersionNumber"] + "', " +
                                      "'" + dataRow["CurrentBuildName"] + "', " +
                                      "'" + dataRow["CurrentLastAssociatedChangeset"] +
                                      "'" + dataRow["DeploymentDate"] + "', " +
                                      "'" + dataRow["CreatedDateTime"] + "', " +
                                      "'" + dataRow["ModifiedDateTime"] + "', " +
                                      "'" + dataRow["Deleted"] + "', " +
                                      " '" + currentDateTimeUtc + "')";
        var sqlcmd = new SqlCommand(QueryUpdateOrInsert, dbConnection);
        var sda = new SqlDataAdapter(sqlcmd);
        var sqlexe = sqlcmd.ExecuteNonQuery();
    }
    catch (Exception Exception)
    {
        MessageBox.Show(Exception.Message);
    }
}
dbConnection.Close();

1 个答案:

答案 0 :(得分:2)

问题是您没有使用SQLite命令/数据适配器,而是使用专为SQL Server设计的适配器。您需要安装System.Data.SQLite .net Adapter并使用正确的Sqlite连接,命令和适配器:SQLiteConnectionSQLiteCommandSQLiteDataAdapter