Configurazione di parametri e tipi di dati dei parametriConfiguring parameters and parameter data types
Gli oggetti comando usano i parametri per passare valori a istruzioni o stored procedure SQL, fornendo la verifica e la convalida dei tipi.Command objects use parameters to pass values to SQL statements or stored procedures, providing type checking and validation. A differenza del testo dei comandi, l'input dei parametri viene trattato come valore letterale, non come codice eseguibile.Unlike command text, parameter input is treated as a literal value, not as executable code. In questo modo è possibile difendersi da attacchi SQL injection, in cui l'autore di un attacco inserisce un comando che compromette la sicurezza del server in un'istruzione SQL.This helps guard against "SQL injection" attacks, in which an attacker inserts a command that compromises security on the server into an SQL statement.
I comandi con parametri possono anche migliorare le prestazioni di esecuzione delle query in quanto aiutano il server database a ottenere una corrispondenza accurata tra il comando in arrivo e un piano di query memorizzato nella cache appropriato.Parameterized commands can also improve query execution performance, because they help the database server accurately match the incoming command with a proper cached query plan. Per altre informazioni, vedere memorizzazione nella cache e riutilizzo del piano di esecuzione e parametri e riutilizzo del piano di esecuzione.For more information, see Execution Plan Caching and Reuse and Parameters and Execution Plan Reuse. Oltre ai vantaggi in termini di sicurezza e prestazioni, i comandi con parametri offrono un metodo pratico per organizzare i valori passati a un'origine dati.In addition to the security and performance benefits, parameterized commands provide a convenient method for organizing values passed to a data source.
Per creare un oggetto DbParameter , è possibile usare il relativo costruttore o aggiungerlo all'oggetto DbParameterCollection chiamando il metodo Add
della raccolta DbParameterCollection .A DbParameter object can be created by using its constructor, or by adding it to the DbParameterCollection by calling the Add
method of the DbParameterCollection collection. Il metodo Add
accetta come input argomenti del costruttore o un oggetto parametro esistente, a seconda del provider di dati.The Add
method will take as input either constructor arguments or an existing parameter object, depending on the data provider.
Specifica della proprietà ParameterDirectionSupplying the ParameterDirection property
Quando si aggiungono parametri, è necessario fornire una proprietà ParameterDirection per i parametri diversi da quelli di input.When adding parameters, you must supply a ParameterDirection property for parameters other than input parameters. La tabella seguente illustra i valori ParameterDirection
che è possibile usare con l'enumerazione ParameterDirection .The following table shows the ParameterDirection
values that you can use with the ParameterDirection enumeration.
Nome del membroMember name | DescrizioneDescription |
---|---|
Input | Il parametro è un parametro di input.The parameter is an input parameter. Questo è il valore predefinito.This is the default. |
InputOutput | Il parametro può essere sia di input che di output.The parameter can perform both input and output. |
Output | Il parametro è un parametro di output.The parameter is an output parameter. |
ReturnValue | Il parametro rappresenta un valore restituito da un'operazione quale una stored procedure, una funzione predefinita o una funzione definita dall'utente.The parameter represents a return value from an operation such as a stored procedure, built-in function, or user-defined function. |
Utilizzo dei segnaposto dei parametriWorking with parameter placeholders
La sintassi per i segnaposto dei parametri varia in base all'origine dati.The syntax for parameter placeholders depends on the data source. I provider di dati .NET Framework gestiscono in modo diverso la denominazione e la specifica di parametri e segnaposto di parametri.The .NET Framework data providers handle naming and specifying parameters and parameter placeholders differently. Questa sintassi è personalizzata in base a un'origine dati specifica, come descritto nella tabella seguente.This syntax is customized to a specific data source, as described in the following table.
Provider di datiData provider | Sintassi di denominazione di parametriParameter naming syntax |
---|---|
System.Data.SqlClient | Usa parametri denominati nel formato @ nomeparametro.Uses named parameters in the format @ parametername. |
System.Data.OleDb | Usa marcatori dei parametri di posizione indicati da un punto interrogativo (? ).Uses positional parameter markers indicated by a question mark (? ). |
System.Data.Odbc | Usa marcatori dei parametri di posizione indicati da un punto interrogativo (? ).Uses positional parameter markers indicated by a question mark (? ). |
System.Data.OracleClient | Usa parametri denominati nel formato : parmname (o parmname).Uses named parameters in the format : parmname (or parmname). |
Specifica di tipi di dati dei parametriSpecifying parameter data types
Il tipo di dati di un parametro è specifico del provider di dati .NET Framework.The data type of a parameter is specific to the .NET Framework data provider. Se si specifica il tipo, il valore di viene convertito nel Parameter
tipo di provider di dati .NET Framework prima di passare il valore all'origine dati.Specifying the type converts the value of the Parameter
to the .NET Framework data provider type before passing the value to the data source. È inoltre possibile specificare il tipo di un oggetto Parameter
in modo generico impostando la proprietà DbType
dell'oggetto Parameter
su un determinato oggetto DbType.You may also specify the type of a Parameter
in a generic manner by setting the DbType
property of the Parameter
object to a particular DbType.
Il tipo di provider di dati .NET Framework di un Parameter
oggetto viene dedotto dal tipo di .NET Framework dell' Value
Parameter
oggetto o dall'oggetto DbType
dell' Parameter
oggetto.The .NET Framework data provider type of a Parameter
object is inferred from the .NET Framework type of the Value
of the Parameter
object, or from the DbType
of the Parameter
object. La tabella seguente illustra il tipo Parameter
dedotto in base all'oggetto passato come valore di Parameter
o all'oggetto DbType
specificato.The following table shows the inferred Parameter
type based on the object passed as the Parameter
value or the specified DbType
.
Tipo .NET Framework.NET Framework type | DbTypeDbType | SqlDbTypeSqlDbType | OleDbTypeOleDbType | OdbcTypeOdbcType | OracleTypeOracleType |
---|---|---|---|---|---|
Boolean | BooleanBoolean | bitBit | BooleanBoolean | bitBit | ByteByte |
Byte | ByteByte | TinyIntTinyInt | UnsignedTinyIntUnsignedTinyInt | TinyIntTinyInt | ByteByte |
byte[]byte[] | BinarioBinary | VarBinary.VarBinary. Questa conversione implicita non riesce se la matrice di byte è maggiore della dimensione massima di VarBinary, ovvero 8000 byte. Per le matrici di byte maggiori di 8000 byte, impostare in modo esplicito SqlDbType .This implicit conversion will fail if the byte array is larger than the maximum size of a VarBinary, which is 8000 bytes.For byte arrays larger than 8000 bytes, explicitly set the SqlDbType. | VarBinaryVarBinary | BinarioBinary | RawRaw |
Char | L'inferenza di un oggetto SqlDbType da char non è supportata.Inferring a SqlDbType from char is not supported. | CharChar | CharChar | ByteByte | |
DateTime | DatetimeDateTime | DatetimeDateTime | DBTimeStampDBTimeStamp | DatetimeDateTime | DatetimeDateTime |
DateTimeOffset | DateTimeOffsetDateTimeOffset | DateTimeOffset in SQL Server 2008.DateTimeOffset in SQL Server 2008. L'inferenza di un oggetto SqlDbType da DateTimeOffset non è supportata nelle versioni di SQL Server precedenti a SQL Server 2008.Inferring a SqlDbType from DateTimeOffset is not supported in versions of SQL Server earlier than SQL Server 2008. | DatetimeDateTime | ||
Decimal | DecimalDecimal | DecimalDecimal | DecimalDecimal | NumericNumeric | NumberNumber |
Double | DoubleDouble | FloatFloat | DoubleDouble | DoubleDouble | DoubleDouble |
Single | SingleSingle | RealReal | SingleSingle | RealReal | FloatFloat |
Guid | GuidGuid | UniqueIdentifierUniqueIdentifier | GuidGuid | UniqueIdentifierUniqueIdentifier | RawRaw |
Int16 | Int16Int16 | SmallIntSmallInt | SmallIntSmallInt | SmallIntSmallInt | Int16Int16 |
Int32 | Int32Int32 | IntInt | IntInt | IntInt | Int32Int32 |
Int64 | Int64Int64 | BigIntBigInt | BigIntBigInt | BigIntBigInt | NumberNumber |
Object | OggettoObject | VariantVariant | VariantVariant | L'inferenza di un oggetto OdbcType da Object non è supportata.Inferring an OdbcType from Object is not supported. | BLOBBlob |
String | stringString | NVarChar.NVarChar. La conversione implicita non riesce se la stringa ha una dimensione superiore a quella massima di NVarChar, che è di 4000 caratteri.This implicit conversion will fail if the string is larger than the maximum size of an NVarChar, which is 4000 characters. Per le stringhe maggiori di 4000 caratteri, impostare in modo esplicito SqlDbType.For strings larger than 4000 characters, explicitly set the SqlDbType. | VarWCharVarWChar | NVarCharNVarChar | NVarCharNVarChar |
TimeSpan | OraTime | Time in SQL Server 2008.Time in SQL Server 2008. L'inferenza di un oggetto SqlDbType da TimeSpan non è supportata nelle versioni di SQL Server precedenti a SQL Server 2008.Inferring a SqlDbType from TimeSpan is not supported in versions of SQL Server earlier than SQL Server 2008. | DBTimeDBTime | OraTime | DatetimeDateTime |
UInt16 | UInt16UInt16 | L'inferenza di un oggetto SqlDbType da UInt16 non è supportata.Inferring a SqlDbType from UInt16 is not supported. | UnsignedSmallIntUnsignedSmallInt | IntInt | UInt16UInt16 |
UInt32 | UInt32UInt32 | L'inferenza di un oggetto SqlDbType da UInt32 non è supportata.Inferring a SqlDbType from UInt32 is not supported. | UnsignedIntUnsignedInt | BigIntBigInt | UInt32UInt32 |
UInt64 | UInt64UInt64 | L'inferenza di un oggetto SqlDbType da UInt64 non è supportata.Inferring a SqlDbType from UInt64 is not supported. | UnsignedBigIntUnsignedBigInt | NumericNumeric | NumberNumber |
AnsiStringAnsiString | VarCharVarChar | VarCharVarChar | VarCharVarChar | VarCharVarChar | |
AnsiStringFixedLengthAnsiStringFixedLength | CharChar | CharChar | CharChar | CharChar | |
ValutaCurrency | MoneyMoney | ValutaCurrency | L'inferenza di un oggetto OdbcType da Currency non è supportata.Inferring an OdbcType from Currency is not supported. |
NumberNumber | |
DataDate | Date in SQL Server 2008.Date in SQL Server 2008. L'inferenza di un oggetto SqlDbType da Date non è supportata nelle versioni di SQL Server precedenti a SQL Server 2008.Inferring a SqlDbType from Date is not supported in versions of SQL Server earlier than SQL Server 2008. | DBDateDBDate | DataDate | DatetimeDateTime | |
SByteSByte | L'inferenza di un oggetto SqlDbType da SByte non è supportata.Inferring a SqlDbType from SByte is not supported. | TinyIntTinyInt | L'inferenza di un oggetto OdbcType da SByte non è supportata.Inferring an OdbcType from SByte is not supported. |
SByteSByte | |
StringFixedLengthStringFixedLength | NCharNChar | WCharWChar | NCharNChar | NCharNChar | |
OraTime | Time in SQL Server 2008.Time in SQL Server 2008. L'inferenza di un oggetto SqlDbType da Time non è supportata nelle versioni di SQL Server precedenti a SQL Server 2008.Inferring a SqlDbType from Time is not supported in versions of SQL Server earlier than SQL Server 2008. | DBTimeDBTime | OraTime | DatetimeDateTime | |
VarNumericVarNumeric | L'inferenza di un oggetto SqlDbType da VarNumeric non è supportata.Inferring a SqlDbType from VarNumeric is not supported. | VarNumericVarNumeric | L'inferenza di un oggetto OdbcType da VarNumeric non è supportata.Inferring an OdbcType from VarNumeric is not supported. |
NumberNumber | |
Tipo di oggetto definito dall'utente (oggetto con SqlUserDefinedAggregateAttributeuser-defined type (an object with SqlUserDefinedAggregateAttribute | Object o String, a seconda del provider (SqlClient restituisce sempre Object, ODBC restituisce sempre String e il provider di dati gestito OleDb può vedere entrambiObject or String, depending the provider (SqlClient always returns an Object, Odbc always returns a String, and the OleDb managed data provider can see either | SqlDbType.Udt se SqlUserDefinedTypeAttribute è in caso contrario, altrimenti VariantSqlDbType.Udt if SqlUserDefinedTypeAttribute is present, otherwise Variant | OleDbType.VarWChar (se il valore è null) in caso contrario OleDbType.Variant.OleDbType.VarWChar (if value is null) otherwise OleDbType.Variant. | OdbcType.NVarCharOdbcType.NVarChar | non supportatonot supported |
Nota
Le conversioni da Decimal in altri tipi sono conversioni di restrizione che arrotondano il valore Decimal al valore integer più vicino che tende allo zero.Conversions from decimal to other types are narrowing conversions that round the decimal value to the nearest integer value toward zero. Se non è possibile rappresentare il risultato della conversione nel tipo di destinazione, verrà generata un'eccezione OverflowException .If the result of the conversion is not representable in the destination type, an OverflowException is thrown.
Nota
Quando si invia un valore di parametro null al server, è necessario specificare DBNull , non null
( Nothing
in Visual Basic).When you send a null parameter value to the server, you must specify DBNull, not null
(Nothing
in Visual Basic). Il valore Null nel sistema è un oggetto vuoto senza alcun valore.The null value in the system is an empty object that has no value. DBNull viene utilizzato per rappresentare i valori Null.DBNull is used to represent null values. Per ulteriori informazioni sui valori null di database, vedere gestione di valori null.For more information about database nulls, see Handling Null Values.
Derivazione di informazioni sui parametriDeriving parameter information
I parametri possono anche essere derivati da una stored procedure usando la classe DbCommandBuilder
.Parameters can also be derived from a stored procedure using the DbCommandBuilder
class. Le classi SqlCommandBuilder
e OleDbCommandBuilder
forniscono un metodo statico, DeriveParameters
, che popola automaticamente la raccolta di parametri di un oggetto comando con le informazioni provenienti da una stored procedure.Both the SqlCommandBuilder
and OleDbCommandBuilder
classes provide a static method, DeriveParameters
, which automatically populates the parameters collection of a command object that uses parameter information from a stored procedure. Si noti che DeriveParameters
sovrascrive qualsiasi informazione esistente sui parametri per il comando.Note that DeriveParameters
overwrites any existing parameter information for the command.
Nota
La derivazione di informazioni sui parametri implica una riduzione delle prestazioni, in quando richiede un round trip aggiuntivo con l'origine dati per recuperare le informazioni.Deriving parameter information incurs a performance penalty because it requires an additional round trip to the data source to retrieve the information. Se le informazioni sui parametri sono note in fase di progettazione, è possibile migliorare le prestazioni dell'applicazione impostando i parametri in modo esplicito.If parameter information is known at design time, you can improve the performance of your application by setting the parameters explicitly.
Per altre informazioni, vedere generazione di comandi con CommandBuilder.For more information, see Generating Commands with CommandBuilders.
Utilizzo di parametri con SqlCommand e un stored procedureUsing parameters with a SqlCommand and a stored procedure
Le stored procedure offrono numerosi vantaggi nelle applicazioni guidate dai dati.Stored procedures offer many advantages in data-driven applications. Usando le stored procedure, le operazioni nel database possono essere incapsulate in un unico comando, ottimizzate per migliorare le prestazioni e rese più sicure con funzioni di sicurezza aggiuntive.By using stored procedures, database operations can be encapsulated in a single command, optimized for best performance, and enhanced with additional security. Sebbene sia possibile chiamare un stored procedure passando il nome del stored procedure seguito da argomenti di parametro come istruzione SQL, l'utilizzo della Parameters raccolta dell'oggetto ADO.NET DbCommand consente di definire in modo più esplicito i parametri di stored procedure e di accedere ai parametri di output e ai valori restituiti.Although a stored procedure can be called by passing the stored procedure name followed by parameter arguments as an SQL statement, by using the Parameters collection of the ADO.NET DbCommand object enables you to more explicitly define stored procedure parameters, and to access output parameters and return values.
Nota
Le istruzioni con parametri vengono eseguite sul server tramite sp_executesql,
, che consente il riutilizzo del piano di query.Parameterized statements are executed on the server by using sp_executesql,
which allows for query plan reuse. I cursori o le variabili locali del batch sp_executesql
non sono visibili per il batch che chiama sp_executesql
.Local cursors or variables in the sp_executesql
batch are not visible to the batch that calls sp_executesql
. Le modifiche apportate al contesto del database durano solo fino al termine dell'esecuzione dell'istruzione sp_executesql
.Changes in database context last only to the end of the sp_executesql
statement. Per ulteriori informazioni, vedere sp_executesql (Transact-SQL).For more information, see sp_executesql (Transact-SQL).
Quando si usano parametri con SqlCommand per eseguire una stored procedure di SQL Server, i nomi dei parametri aggiunti alla raccolta Parameters devono corrispondere ai nomi dei marcatori dei parametri nella stored procedure.When using parameters with a SqlCommand to execute a SQL Server stored procedure, the names of the parameters added to the Parameters collection must match the names of the parameter markers in the stored procedure. Il .NET Framework provider di dati per SQL Server non supporta il segnaposto punto interrogativo (?) per il passaggio di parametri a un'istruzione SQL o a una stored procedure.The .NET Framework Data Provider for SQL Server does not support the question mark (?) placeholder for passing parameters to an SQL statement or a stored procedure. I parametri nella stored procedure vengono trattati come parametri denominati e vengono ricercati marcatori di parametri corrispondenti.It treats parameters in the stored procedure as named parameters and searches for matching parameter markers. Ad esempio, la stored procedure CustOrderHist
è definita con un parametro denominato @CustomerID
.For example, the CustOrderHist
stored procedure is defined by using a parameter named @CustomerID
. Quando il codice esegue la stored procedure deve usare anche un parametro denominato @CustomerID
.When your code executes the stored procedure, it must also use a parameter named @CustomerID
.
CREATE PROCEDURE dbo.CustOrderHist @CustomerID varchar(5)
EsempioExample
In questo esempio viene illustrato come chiamare una stored procedure di SQL Server nel database di esempio Northwind
.This example demonstrates how to call a SQL Server stored procedure in the Northwind
sample database. Il nome della stored procedure è dbo.SalesByCategory
e accetta un parametro di input denominato @CategoryName
con un tipo di dati nvarchar(15)
.The name of the stored procedure is dbo.SalesByCategory
and it has an input parameter named @CategoryName
with a data type of nvarchar(15)
. Nel codice viene creato un nuovo oggetto SqlConnection all'interno di un blocco using, in modo che la connessione venga eliminata al termine della procedura.The code creates a new SqlConnection inside a using block so that the connection is disposed when the procedure ends. Vengono creati gli oggetti SqlCommand e SqlParameter e vengono impostate le relative proprietà.The SqlCommand and SqlParameter objects are created, and their properties set. Un oggetto SqlDataReader esegue SqlCommand
e restituisce il set di risultati dalla stored procedure, visualizzando l'output nella finestra della console.A SqlDataReader executes the SqlCommand
and returns the result set from the stored procedure, displaying the output in the console window.
Nota
Anziché creare oggetti SqlCommand
e SqlParameter
e impostare quindi le proprietà in istruzioni distinte, è possibile scegliere di usare uno dei costruttori di overload per impostare più proprietà in una singola istruzione.Instead of creating SqlCommand
and SqlParameter
objects and then setting properties in separate statements, you can instead elect to use one of the overloaded constructors to set multiple properties in a single statement.
static void GetSalesByCategory(string connectionString,
string categoryName)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
// Create the command and set its properties.
SqlCommand command = new SqlCommand();
command.Connection = connection;
command.CommandText = "SalesByCategory";
command.CommandType = CommandType.StoredProcedure;
// Add the input parameter and set its properties.
SqlParameter parameter = new SqlParameter();
parameter.ParameterName = "@CategoryName";
parameter.SqlDbType = SqlDbType.NVarChar;
parameter.Direction = ParameterDirection.Input;
parameter.Value = categoryName;
// Add the parameter to the Parameters collection.
command.Parameters.Add(parameter);
// Open the connection and execute the reader.
connection.Open();
using (SqlDataReader reader = command.ExecuteReader())
{
if (reader.HasRows)
{
while (reader.Read())
{
Console.WriteLine("{0}: {1:C}", reader[0], reader[1]);
}
}
else
{
Console.WriteLine("No rows found.");
}
reader.Close();
}
}
}
Shared Sub GetSalesByCategory(ByVal connectionString As String, _
ByVal categoryName As String)
Using connection As New SqlConnection(connectionString)
' Create the command and set its properties.
Dim command As SqlCommand = New SqlCommand()
command.Connection = connection
command.CommandText = "SalesByCategory"
command.CommandType = CommandType.StoredProcedure
' Add the input parameter and set its properties.
Dim parameter As New SqlParameter()
parameter.ParameterName = "@CategoryName"
parameter.SqlDbType = SqlDbType.NVarChar
parameter.Direction = ParameterDirection.Input
parameter.Value = categoryName
' Add the parameter to the Parameters collection.
command.Parameters.Add(parameter)
' Open the connection and execute the reader.
connection.Open()
Using reader As SqlDataReader = command.ExecuteReader()
If reader.HasRows Then
Do While reader.Read()
Console.WriteLine("{0}: {1:C}", _
reader(0), reader(1))
Loop
Else
Console.WriteLine("No rows returned.")
End If
End Using
End Using
End Sub
Utilizzo di parametri con OleDbCommand o OdbcCommandUsing parameters with an OleDbCommand or OdbcCommand
Quando si usano parametri con OleDbCommand o OdbcCommand, l'ordine dei parametri aggiunti alla raccolta Parameters
deve corrispondere all'ordine dei parametri definiti nella stored procedure.When using parameters with an OleDbCommand or OdbcCommand, the order of the parameters added to the Parameters
collection must match the order of the parameters defined in your stored procedure. Il .NET Framework provider di dati per OLE DB e .NET Framework provider di dati per ODBC considera i parametri in un stored procedure come segnaposto e applica i valori dei parametri nell'ordine.The .NET Framework Data Provider for OLE DB and .NET Framework Data Provider for ODBC treat parameters in a stored procedure as placeholders and apply parameter values in order. Inoltre, i parametri dei valori restituiti devono essere i primi parametri aggiunti alla raccolta Parameters
.In addition, return value parameters must be the first parameters added to the Parameters
collection.
Il .NET Framework provider di dati per OLE DB e .NET Framework provider di dati per ODBC non supporta i parametri denominati per il passaggio di parametri a un'istruzione SQL o a un stored procedure.The .NET Framework Data Provider for OLE DB and .NET Framework Data Provider for ODBC do not support named parameters for passing parameters to an SQL statement or a stored procedure. In questo caso è necessario usare il punto interrogativo (?) come segnaposto, come nell'esempio seguente.In this case, you must use the question mark (?) placeholder, as in the following example.
SELECT * FROM Customers WHERE CustomerID = ?
Di conseguenza, l'ordine in cui vengono aggiunti gli oggetti Parameter
alla raccolta Parameters
deve corrispondere esattamente alla posizione del segnaposto punto interrogativo (?)As a result, the order in which Parameter
objects are added to the Parameters
collection must directly correspond to the position of the ? usato per il parametro.placeholder for the parameter.
Esempio di OleDbOleDb Example
Dim command As OleDbCommand = New OleDbCommand( _
"SampleProc", connection)
command.CommandType = CommandType.StoredProcedure
Dim parameter As OleDbParameter = command.Parameters.Add( _
"RETURN_VALUE", OleDbType.Integer)
parameter.Direction = ParameterDirection.ReturnValue
parameter = command.Parameters.Add( _
"@InputParm", OleDbType.VarChar, 12)
parameter.Value = "Sample Value"
parameter = command.Parameters.Add( _
"@OutputParm", OleDbType.VarChar, 28)
parameter.Direction = ParameterDirection.Output
OleDbCommand command = new OleDbCommand("SampleProc", connection);
command.CommandType = CommandType.StoredProcedure;
OleDbParameter parameter = command.Parameters.Add(
"RETURN_VALUE", OleDbType.Integer);
parameter.Direction = ParameterDirection.ReturnValue;
parameter = command.Parameters.Add(
"@InputParm", OleDbType.VarChar, 12);
parameter.Value = "Sample Value";
parameter = command.Parameters.Add(
"@OutputParm", OleDbType.VarChar, 28);
parameter.Direction = ParameterDirection.Output;
Esempio di OdbcOdbc Example
Dim command As OdbcCommand = New OdbcCommand( _
"{ ? = CALL SampleProc(?, ?) }", connection)
command.CommandType = CommandType.StoredProcedure
Dim parameter As OdbcParameter = command.Parameters.Add("RETURN_VALUE", OdbcType.Int)
parameter.Direction = ParameterDirection.ReturnValue
parameter = command.Parameters.Add( _
"@InputParm", OdbcType.VarChar, 12)
parameter.Value = "Sample Value"
parameter = command.Parameters.Add( _
"@OutputParm", OdbcType.VarChar, 28)
parameter.Direction = ParameterDirection.Output
OdbcCommand command = new OdbcCommand( _
"{ ? = CALL SampleProc(?, ?) }", connection);
command.CommandType = CommandType.StoredProcedure;
OdbcParameter parameter = command.Parameters.Add( _
"RETURN_VALUE", OdbcType.Int);
parameter.Direction = ParameterDirection.ReturnValue;
parameter = command.Parameters.Add( _
"@InputParm", OdbcType.VarChar, 12);
parameter.Value = "Sample Value";
parameter = command.Parameters.Add( _
"@OutputParm", OdbcType.VarChar, 28);
parameter.Direction = ParameterDirection.Output;