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# 关键字';或';_C#_Sqlite - Fatal编程技术网

C# 关键字';或';

C# 关键字';或';,c#,sqlite,C#,Sqlite,我试图使用以下查询将其插入或替换到SQLite数据库中: INSERT OR REPLACE INTO VersionNumbers (VersionNumberID, ENVID, EnvShortName, VersionNumber, BuildNumber, SourceGetVersion, DeploymentDate, CreatedDateTime, ModifiedDateTime, Deleted, LastGetFromServerDateTime) Values ('da

我试图使用以下查询将其插入或替换到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#传入相同的查询,我会得到错误“关键字'OR'附近的语法不正确”

C#


问题在于,您使用的不是
SQLite
命令/数据适配器,而是为sqlserver设计的适配器。您需要安装并使用正确的Sqlite连接、命令和适配器:
SQLiteConnection
SQLiteCommand
SQLiteDataAdapter

我从未见过
插入或替换
。我会尝试只使用
REPLACE
,因为如果该行不存在,此命令将插入该行。您是否尝试只使用REPLACE-INTO而不是insert或REPLACE-INTO?@Pikoh,我刚刚尝试使用REPLACE,现在出现以下错误:“关键字'INTO'附近的语法不正确。”数据库是SQLite吗?@Pikoh是的,它是由SQLite创建的.db
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();