有人可以帮助我了解我在下面的代码中做错了什么吗?://....internal static string InsertCorrespondenceRecipientItem(TbEmail email, Guid correspondenceId, Guid contactId) => $@" INSERT INTO CorrespondenceRecipientItems (Id, DateSent, Subject, ToEmail, [CorrespondenceId] , [ToId], [CorrespondenceRecipientId]) VALUES ('{email.Guid}', '{email.DateSent}', @subject, @emailString, '{correspondenceId}', '{contactId}', '{email.Guid}') "; var sqlItemsUpdate = SqlHelpers.InsertCorrespondenceRecipientItem(item.email, correspondence.Guid, fromId); var subject = item.email.Subject.Trim(); var emailString = item.email.EmailAddressString.Trim(); await _db.Database.ExecuteSqlCommandAsync(sqlItemsUpdate, new SqlParameter("@subject", subject), new SqlParameter("@emailString", emailString));数据库中的结果是'7F856136-0036-4F68-249F-08D5AB631656', @subject, @emailString为什么执行不设置参数的值?
2 回答
茅侃侃
TA贡献1842条经验 获得超21个赞
使用参数化查询:
query = INSERT INTO ReportingLogs ([UserName],[FirstName]) 值 (@username,@firstname)
SqlCommand sqlCommand = new SqlCommand(cmdText, connection); SqlCommand.Parameters.Add("@userName", SqlDbType.VarChar).Value = 用户名
//在finally块中关闭连接或使用using()语句
- 2 回答
- 0 关注
- 149 浏览
添加回答
举报
0/150
提交
取消