OdbcParameter.ParameterName 属性

定义

获取或设置 OdbcParameter 的名称。

public:
 virtual property System::String ^ ParameterName { System::String ^ get(); void set(System::String ^ value); };
public:
 property System::String ^ ParameterName { System::String ^ get(); void set(System::String ^ value); };
public override string ParameterName { get; set; }
public string ParameterName { get; set; }
member this.ParameterName : string with get, set
Public Overrides Property ParameterName As String
Public Property ParameterName As String

属性值

String

OdbcParameter 的名称。 默认值为空字符串("")。

实现

示例

以下示例假定数据源具有表名 MyTable 和名为 MyProc 的存储过程,该存储过程定义为:

CREATE TABLE MyTable (col1 int, col2 smallmoney, col3 decimal)  
CREATE PROC MyProc (@p1 int, @p2 smallmoney, @p3 decimal) AS INSERT INTO MyTable VALUES (@p1, @p2, @p3)  

以下示例创建参数并调用 MyProc 存储过程:

Public Sub CreateMyProc(connection As OdbcConnection)  

   Dim command As OdbcCommand = connection.CreateCommand()  

   command.CommandText = "{ call MyProc(?,?,?) }"  
   command.Parameters.Add("", OdbcType.Int).Value = 1  
   command.Parameters.Add("", OdbcType.Decimal).Value = 2  
   command.Parameters.Add("", OdbcType.Decimal).Value = 3  

End Sub  
public void CreateMyProc(OdbcConnection connection)   
{  
   OdbcCommand command = myConnection.CreateCommand();  

   command.CommandText = "{ call MyProc(?,?,?) }";  
   command.Parameters.Add("", OdbcType.Int).Value = 1;  
   command.Parameters.Add("", OdbcType.Decimal).Value = 2;  
   command.Parameters.Add("", OdbcType.Decimal).Value = 3;  
}  

注解

ODBC .NET 提供程序使用在命令文本的语法中用问号 (?) 标记的位置参数,而不是命名参数。 存储过程接受的参数对象或参数化SQL语句接受的参数对象OdbcParameterCollection彼此对应,具体取决于对象插入到集合中的顺序OdbcParameter,而不是参数名称。 可以提供参数名称,但在参数对象绑定期间将被忽略。

适用于

另请参阅