我有一个合并语句,它将值插入数据库。我遇到异常错误的异常点
MERGE 语句必须以分号 (;) 结束。
这是我的声明。谁能指出我错过了什么?
using (var masterDb = new SqlConnection(ConfigurationManager.ConnectionStrings["MasterDB"].ConnectionString))
{
masterDb.Open();
if (data != null)
try
{
conn.Execute(
"MERGE INTO [dbo].[FormSubmissions] AS TARGET " +
"USING(VALUES(@Id,@CreatedAt,@UpdatedAt,@IsComplete,@FormId,[@Source],@SentEmail)) AS SOURCE (Id,CreatedAt,UpdatedAt,IsComplete,FormId,[Source],SentEmail) " +
"ON TARGET.Id = SOURCE.Id " +
"WHEN MATCHED THEN " +
"UPDATE SET CreatedAt = SOURCE.CreatedAt,UpdatedAt = SOURCE.UpdatedAt,IsComplete = SOURCE.IsComplete, FormId = SOURCE.FormId, [Source] = SOURCE.[Source], SentEmail = SOURCE.SentEmail " +
"WHEN NOT MATCHED BY TARGET THEN " +
"INSERT(Id,CreatedAt,UpdatedAt,IsComplete,FormId,[Source],SentEmail) " +
"VALUES(Id,CreatedAt,UpdatedAt,IsComplete,FormId,[Source],SentEmail)",
new
{
Id = formSubmissionsId,
CreatedAt = data.CreatedAt,
UpdatedAt = data.UpdatedAt,
IsComplete = data.IsComplete,
FormId = data.FormId,
Source = data.Source,
SentEmail = data.SentEmail
});
}
catch (Exception ex)
{
throw;
}
finally
{
masterDb.Close();
}
};
conn.Close();
}