關於 ObjectDataSource 的 OldValuesParameterFormatString
使用向导配置ObjectDataSource 的另一个影响是,Visual Studio 将OldValuesParameterFormatString属性 设为 original_{0} 。此属性值用于包含被编辑数据的初始值,在下列两种场景中非常有用 :
用户在编辑记录时可以更改主键值。在这种情况下,必须同时提供新的主键值和初始主键值。这样,我们才能查找到带有初始主键值的记录,并作相应的更新。
使用并发优化。并发优化技术用于确保两个同时操作的用户不会覆盖彼此的更改。后面的教程将对此作详细讲解。
OldValuesParameterFormatString 属性表示了基础对象的更新和删除方法中对应初始值的输入参数的名称。在讨论并发优化时,我将对此属性及其作用作详细介绍。此处提到此属性是因为,我们的 BLL 的方法不接受初始值,因此必须将它删除。如果 OldValuesParameterFormatString 属性没有设为默认值 {0} ,Web 数据控件试图调用 ObjectDataSource 的 Update() 或 Delete() 方法时会出现错误。因为 ObjectDataSource 将试图同时传递指定的 UpdateParameters (或 DeleteParameters )和初始值参数。
如果现在对此问题不是很清楚也没关系,我们将在 后面的教程中详细研究该属性及其用途。现在,只需确保从声明性语法中完全删除此属性的声明,或将它的值设为默认的 {0} 即可。
注意:如果只是从 Design 视图的 Properties 窗口中清除OldValuesParameterFormatString 属性值,该属性在声明性语法中仍然存在,但被设置为空字符串。遗憾的是,这也会导致出现上面提到的问题。因此,应从声明性语法中将此属性删除,或者从 Properties 窗口中将属性值设为默认的 {0} 。
---------------------------------------------------
我已在 Properties 窗口中将属性值设为默认的 {0} ,為什麼 還會出現:
Value cannot be null.
Parameter name: Original_co
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: Original_co
Source Error:
Line 2247: }
Line 2248: if ((Original_co == null)) {
Line 2249: throw new System.ArgumentNullException("Original_co");
Line 2250: }
Line 2251: else {