EntLib Way to Bind “Null” Value to Parameter

▼魔方 西西 提交于 2019-12-13 16:22:38

问题


I wish to pass Null Value to the parameter as follow:

_db.AddInParameter(dbCommand, "Id", DBNull.Value, myContactPerson.Id);

I am receiving the following error :

"can not convert "System.DBNull to System.Data.DbType".

I know the meaning of this error.

But i need to supply null value to myContactPerson.Id

How can i achieve this ?


回答1:


If myContactPerson.Id isn't an auto-number, then why not just pass 0.




回答2:


DBType should be passed in that parameter and should match your the dbtype (string, int, etc.) for the table that you are comparing with in your database. You would replace your value field "myContactPerson.Id" with DBNull.Value to always pass the null value.



来源:https://stackoverflow.com/questions/1252677/entlib-way-to-bind-null-value-to-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!