【发布时间】:2020-04-14 22:18:25
【问题描述】:
我正在尝试从 C# 执行存储过程
var dt = new SqlParameter("ExportedOn", DateTime.Now);
context.Database.ExecuteSqlCommand("EXEC LogDataExport @ExportedOn", dt);
存储过程:
CREATE PROCEDURE LogDataExport
(@ExportedOn DATETIME2)
AS
INSERT INTO dbo.DataExportLogging (Id, ExportedOn, Description, Text)
SELECT 1, @ExportedOn, 'asd', 'dsasadfsdag'
GO
我收到一个错误,提示 dt 无法从 NVARCHAR 转换为 Datetime2。
【问题讨论】:
-
尝试在 SqlParameter 上指定数据类型。
dt.SqlDbType = SqlDbType.DateTime2; -
是编译时错误还是运行时错误? 确切错误是什么?
-
请为
DataExportLogging分享CREATE TABLE脚本。
标签: c# sql entity-framework