SQLite关键字'OR'附近语法错误
本文关键字:语法 错误 SQLite OR 关键字 | 更新日期: 2023-09-27 18:18:02
我正在尝试使用以下查询插入或替换到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')
我已经测试了这个使用数据库浏览器的SQLite和执行SQL直接在数据库上,这一切都很好,但如果我通过c#传递相同的查询,我得到错误"语法不正确的关键字'OR'附近。"
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();
问题是您没有使用SQLite
命令/数据适配器,而是为SQL Server设计的。您需要安装System.Data.SQLite .net适配器,并使用正确的Sqlite连接、命令和适配器:SQLiteConnection
、SQLiteCommand
和SQLiteDataAdapter