## 关于 ODP.NET 中 OracleCommand.BindByName 属性

Comparing the Microsoft .NET Framework 1.1 Data Provider for Oracle and the Oracle Data Provider for .NET

By default, ODP.NET parameters for OracleCommand.CommandType = Text commands are bound by position. The OracleCommand class provides a BindByName property—set this property to true to bind parameters by name instead of by position. The Microsoft provider always binds parameters by name.

BindByName system level setting

Is there or will there ever be a system level parameter for OracleCommand.BindByName. It's very frustrating to have to set it everywhere, especially if you have common frameworks that use the generate IDbCommand/IDbConnection interfaces with a Connection factory.
We had to put an explicit type test into our Persistance framework just to see if it was an OracleCommand and set that property. That means EVERY call regardless of the target database has to go through that check

OracleCommand Class

##### BindByName

This property specifies the binding method in the collection.

Declaration

// C#
public bool BindByName {get; set;}


Property Value

Returns true if the parameters are bound by name; returns false if the parameters are bound by position.

Remarks

Default = false.

BindByName is ignored under the following conditions:

• The value of the XmlCommandType property is Insert, Update, or Delete.

• The value of the XmlCommandType property is Query, but there are no parameters set on the OracleCommand.

If the XmlCommandType property is OracleXmlCommandType.Query and any parameters are set on the OracleCommand, the BindByName property must be set to true. Otherwise, the following OracleCommand methods throw an InvalidOperationException.

• ExecuteNonQuery

• ExecuteXmlReader

• ExecuteStream

• ExecuteToStream

posted on 2007-07-16 22:16  gucs  阅读(2968)  评论(2编辑  收藏