![](/img/trans.png)
[英]How to capture a null Parameter and allow Parsing with DBNull in ADO.NET
[英]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.