I assume SqlParameter.IsNullable only makes sense when…?

你离开我真会死。 提交于 2019-12-08 00:21:38

问题


1) When SqlParameter.IsNullable is set to true, received null value is converted to DBNull.Value and sent to database. Thus I would assume setting IsNullable to true only makes sense when GridView’s Parameter.ConvertEmptyStringToNull is also set to true?

2) Both GridView’s and ObjectDataSource’s parameters have a ConvertEmptyStringToNull property. But is there ever a situation where ( when trying to update data source ):

• where we should set GridView’s Parameter.ConvertEmptyStringToNull to true, but then set ObjectDataSource’s Parameter.ConvertEmptyStringToNull to false?!

• or where we should set GridView’s Parameter.ConvertEmptyStringToNull to true, but SqlDataSource’s SqlParameter.IsNullable to false?


回答1:


Ans : 1: When SqlParameter.IsNullable is set to true, received null value is converted to DBNull.Value and sent to database. Thus I would assume setting IsNullable to true only makes sense when GridView’s Parameter.ConvertEmptyStringToNull is also set to true? - simply yes




回答2:


The responses in general are "NO" to all your questions, because not always there is a DataGrid, which is not the only way to show data and or get an input from the user.

If your user interface provides data in another way (e.g. DetailView, FromView, hand-made-window-or-page, etc...), or you have not UI at all, and your data come from another source, you may have to deal with IsNullable and/or ConvertEmptyStringToNull properties independently from a DataGrid that does not exists!

IsNullable in particular, when you are calling stored procedures, should match the sp's definition of the parameter.



来源:https://stackoverflow.com/questions/941913/i-assume-sqlparameter-isnullable-only-makes-sense-when

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