【发布时间】:2020-11-03 15:32:33
【问题描述】:
我的一个参数如下所示:
cmd.Parameters.Add("@last_sign_in_at", SqlDbType.DateTime).Value = user.last_sign_in_at;
我知道用户在last_sign_in_at 中有空值。数据库接受此列的空值,但出现异常:
SqlException:参数化查询 '(@id int,@name nvarchar(18),@username nvarchar(11),@state nvarch' 需要参数 '@last_sign_in_at',但未提供。
【问题讨论】:
-
提示:如果您使用 Dapper,它会为您为您提供类似的东西,并避免大量代码:
connection.Execute(@"...SQL...", new { user.last_sign_in_at });