为了账号安全,请及时绑定邮箱和手机立即绑定

SqlParameter 设置值不起作用

SqlParameter 设置值不起作用

C#
慕码人2483693 2021-06-04 15:06:29
有人可以帮助我了解我在下面的代码中做错了什么吗?://....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()语句



查看完整回答
反对 回复 2021-06-05
  • 2 回答
  • 0 关注
  • 136 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信