繁体   English   中英

如何在ADO.Net中潜在地将null作为参数传递

[英]How to potentially pass null in as a parameter in ADO.Net

我正在尝试使用ADO.NET将参数传递到存储的proc中。 该参数的类型为int,但数据库中的字段可以为空。 这是我的代码:

AddInParameter(cmd, "@i_Required_License_List_PKID", DbType.Int32, RequiredLicenseListPkid==""? null : Convert.ToInt32(RequiredLicenseListPkid);

当我这样做时,我收到一条错误消息,指出null和int之间没有转换。

我也尝试过DbNull.Value代替null,但结果相同。

我似乎在DbType类中找不到任何可为空的参数类型,但我想知道解决方案是什么。

使用:DBNull.Value;

作为参数的值

AddInParameter(cmd,“ @i_Required_License_List_PKID”,DbType.Int32,RequiredLicenseListPkid ==“”?DBNull.Value:Convert.ToInt32(RequiredLicenseListPkid);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM