Parametreleri ve parametre veri türlerini yapılandırmaConfiguring parameters and parameter data types
Komut nesneleri, tür denetimi ve doğrulama sağlamak için değerleri SQL deyimlerine veya saklı yordamlara geçirmek için parametreler kullanır.Command objects use parameters to pass values to SQL statements or stored procedures, providing type checking and validation. Komut metninin aksine, parametre girişi, çalıştırılabilir kod olarak değil, değişmez değer olarak değerlendirilir.Unlike command text, parameter input is treated as a literal value, not as executable code. Bu, bir saldırganın sunucuda güvenlik altına bir SQL bildirimine güvenmesini sağlayan bir komut eklediği "SQL ekleme" saldırılarına karşı koruma sağlamaya yardımcı olur.This helps guard against "SQL injection" attacks, in which an attacker inserts a command that compromises security on the server into an SQL statement.
Parametreli Komutlar, veritabanı sunucusunun doğru bir önbelleğe alınmış sorgu planıyla gelen komutla doğru bir şekilde eşleştiğinden yardımcı olduklarından sorgu yürütme performansını da iyileştirebilir.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. Daha fazla bilgi için bkz. yürütme planı önbelleğe alma ve yeniden kullanma ve Parametreler ve yürütme planı yeniden kullanımı.For more information, see Execution Plan Caching and Reuse and Parameters and Execution Plan Reuse. Güvenlik ve performans avantajlarına ek olarak, Parametreli Komutlar bir veri kaynağına geçirilen değerleri düzenlemek için kullanışlı bir yöntem sağlar.In addition to the security and performance benefits, parameterized commands provide a convenient method for organizing values passed to a data source.
Bir DbParameter nesnesi, Oluşturucusu kullanılarak veya DbParameterCollection koleksiyonun yöntemi çağırarak öğesine eklenerek oluşturulabilir Add
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. Add
Yöntemi, veri sağlayıcısına bağlı olarak, Oluşturucu bağımsız değişkenleri veya var olan bir parametre nesnesi olarak giriş olarak alır.The Add
method will take as input either constructor arguments or an existing parameter object, depending on the data provider.
ParameterDirection özelliği sağlamaSupplying the ParameterDirection property
Parametreleri eklerken, ParameterDirection Giriş parametrelerinden başka parametreler için bir özellik sağlamalısınız.When adding parameters, you must supply a ParameterDirection property for parameters other than input parameters. Aşağıdaki tabloda, ParameterDirection
numaralandırmada kullanabileceğiniz değerler gösterilmektedir ParameterDirection .The following table shows the ParameterDirection
values that you can use with the ParameterDirection enumeration.
Üye adıMember name | DescriptionDescription |
---|---|
Input | Parametresi bir giriş parametresidir.The parameter is an input parameter. Bu varsayılandır.This is the default. |
InputOutput | Parametresi hem giriş hem de çıkış gerçekleştirebilir.The parameter can perform both input and output. |
Output | Parametresi bir çıkış parametresidir.The parameter is an output parameter. |
ReturnValue | Parametresi, saklı yordam, yerleşik işlev veya Kullanıcı tanımlı işlev gibi bir işlemden bir dönüş değeri temsil eder.The parameter represents a return value from an operation such as a stored procedure, built-in function, or user-defined function. |
Parametre yer tutucuları ile çalışmaWorking with parameter placeholders
Parametre yer tutucuları için sözdizimi veri kaynağına bağlıdır.The syntax for parameter placeholders depends on the data source. .NET Framework veri sağlayıcıları, adlandırma ve parametreleri ve parametre yer tutucuları farklı şekilde belirtmeyi işler.The .NET Framework data providers handle naming and specifying parameters and parameter placeholders differently. Bu söz dizimi, aşağıdaki tabloda açıklandığı gibi belirli bir veri kaynağına özelleştirilir.This syntax is customized to a specific data source, as described in the following table.
Veri sağlayıcısıData provider | Parametre adlandırma sözdizimiParameter naming syntax |
---|---|
System.Data.SqlClient | Parametre adı olarak adlandırılmış parametreleri kullanır @ parametername.Uses named parameters in the format @ parametername. |
System.Data.OleDb | Bir soru işaretiyle () belirtilen Konumsal parametre işaretçilerini kullanır ? .Uses positional parameter markers indicated by a question mark (? ). |
System.Data.Odbc | Bir soru işaretiyle () belirtilen Konumsal parametre işaretçilerini kullanır ? .Uses positional parameter markers indicated by a question mark (? ). |
System.Data.OracleClient | , : Parmname (veya parmname) biçiminde adlandırılmış parametreleri kullanır.Uses named parameters in the format : parmname (or parmname). |
Parametre veri türlerini belirtmeSpecifying parameter data types
Bir parametrenin veri türü .NET Framework veri sağlayıcısına özeldir.The data type of a parameter is specific to the .NET Framework data provider. Türü belirtmek, Parameter
değerini veri kaynağına geçirmeden önce değerini .NET Framework veri sağlayıcısı türüne dönüştürür.Specifying the type converts the value of the Parameter
to the .NET Framework data provider type before passing the value to the data source. Ayrıca, Parameter
DbType
nesnesinin özelliğini belirli bir şekilde ayarlayarak bir genel şekilde türünü de belirtebilirsiniz Parameter
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.
Bir nesnenin .NET Framework veri sağlayıcısı türü, nesnenin Parameter
.NET Framework türünden Value
Parameter
veya nesnesinin içinden algılanır DbType
Parameter
.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. Aşağıdaki tabloda, Parameter
değer olarak geçirilen nesneye Parameter
veya belirtilen değere göre gösterilen tür gösterilmektedir DbType
.The following table shows the inferred Parameter
type based on the object passed as the Parameter
value or the specified DbType
.
.NET Framework türü.NET Framework type | DbTypeDbType | SqlDbTypeSqlDbType | OleDbTypeOleDbType | OdbcTypeOdbcType | OracleTypeOracleType |
---|---|---|---|---|---|
Boolean | BooleBoolean | SürümleriBit | BooleBoolean | SürümleriBit | BaytByte |
Byte | BaytByte | IçTinyInt | UnsignedtınyııntUnsignedTinyInt | IçTinyInt | BaytByte |
Byte []byte[] | İkiliBinary | İkili.VarBinary. Bayt dizisi, bir VarBinary 'ın 8000 bayt olan en büyük boyutundan daha büyükse bu örtük dönüştürme başarısız olur. 8000 bayttan daha büyük bayt dizileri için, açıkça öğesini ayarlayın 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. | IkiliVarBinary | İkiliBinary | HamRaw |
Char | Bir SqlDbType char 'ın bir karakter oluşturma işlemi desteklenmez.Inferring a SqlDbType from char is not supported. | CharChar | CharChar | BaytByte | |
DateTime | DateTimeDateTime | DateTimeDateTime | DBTimeStampDBTimeStamp | DateTimeDateTime | DateTimeDateTime |
DateTimeOffset | DateTimeOffsetDateTimeOffset | SQL Server 2008 ' de DateTimeOffset.DateTimeOffset in SQL Server 2008. SqlDbTypeSQL Server 2008 ' den önceki SQL Server sürümlerinde, DateTimeOffset 'den birInferring a SqlDbType from DateTimeOffset is not supported in versions of SQL Server earlier than SQL Server 2008. | DateTimeDateTime | ||
Decimal | OndalıkDecimal | OndalıkDecimal | OndalıkDecimal | SayısalNumeric | SayıNumber |
Double | ÇiftDouble | FloatFloat | ÇiftDouble | ÇiftDouble | ÇiftDouble |
Single | TekSingle | GerçekReal | TekSingle | GerçekReal | FloatFloat |
Guid | GuidGuid | Benzersiz tanımlayıcıUniqueIdentifier | GuidGuid | Benzersiz tanımlayıcıUniqueIdentifier | HamRaw |
Int16 | Int16Int16 | SmallSmallInt | SmallSmallInt | SmallSmallInt | Int16Int16 |
Int32 | Int32Int32 | intInt | intInt | intInt | Int32Int32 |
Int64 | Int64Int64 | BigIntBigInt | BigIntBigInt | BigIntBigInt | SayıNumber |
Object | NesneObject | DeğişkenVariant | DeğişkenVariant | Nesnesinden OdbcType 'ı göstermek desteklenmez.Inferring an OdbcType from Object is not supported. | BlobBlob |
String | DizeString | NVarChar.NVarChar. Dize, 4000 karakter olan bir NVarChar 'nin en büyük boyutundan daha büyükse bu örtük dönüştürme başarısız olur.This implicit conversion will fail if the string is larger than the maximum size of an NVarChar, which is 4000 characters. 4000 karakterden daha büyük dizeler için, açıkça öğesini ayarlayın SqlDbType .For strings larger than 4000 characters, explicitly set the SqlDbType. | VarWCharVarWChar | NVarCharNVarChar | NVarCharNVarChar |
TimeSpan | SaatTime | SQL Server 2008 ' de zaman.Time in SQL Server 2008. Bir SqlDbType TimeSpan değeri, SQL Server 2008 ' den önceki SQL Server sürümlerinde desteklenmez.Inferring a SqlDbType from TimeSpan is not supported in versions of SQL Server earlier than SQL Server 2008. | DBTimeDBTime | SaatTime | DateTimeDateTime |
UInt16 | UInt16UInt16 | UInt16 'den bir veya daha fazla SqlDbType destek desteklenmez.Inferring a SqlDbType from UInt16 is not supported. | UnsignedSmallIntUnsignedSmallInt | intInt | UInt16UInt16 |
UInt32 | UInt32UInt32 | Bir SqlDbType UInt32 'den bir, göstermek desteklenmez.Inferring a SqlDbType from UInt32 is not supported. | UnsignedIntUnsignedInt | BigIntBigInt | UInt32UInt32 |
UInt64 | UInt64UInt64 | Bir UInt64 'nin bir veya daha fazla SqlDbType olması desteklenmiyor.Inferring a SqlDbType from UInt64 is not supported. | UnsignedBigIntUnsignedBigInt | SayısalNumeric | SayıNumber |
AnsıtringAnsiString | VarCharVarChar | VarCharVarChar | VarCharVarChar | VarCharVarChar | |
AnsiStringFixedLengthAnsiStringFixedLength | CharChar | CharChar | CharChar | CharChar | |
Para BirimiCurrency | ParaMoney | Para BirimiCurrency | İçinden bir, ' den fazla bir OdbcType Currency değer erteleme desteklenmez.Inferring an OdbcType from Currency is not supported. |
SayıNumber | |
TarihDate | SQL Server 2008 ' de tarih.Date in SQL Server 2008. SqlDbTypeSQL Server SQL Server 2008 ' den önceki sürümlerde bir from tarihi arasında bir değer olmaması desteklenmez.Inferring a SqlDbType from Date is not supported in versions of SQL Server earlier than SQL Server 2008. | DBDateDBDate | TarihDate | DateTimeDateTime | |
SByteSByte | Bir SByte 'nin bir listesini göstermek SqlDbType desteklenmez.Inferring a SqlDbType from SByte is not supported. | IçTinyInt | Bir OdbcType SByte 'tan çıkarma desteklenmez.Inferring an OdbcType from SByte is not supported. |
SByteSByte | |
StringFixedLengthStringFixedLength | NCharNChar | WCharWChar | NCharNChar | NCharNChar | |
SaatTime | SQL Server 2008 ' de zaman.Time in SQL Server 2008. SqlDbTypeSQL Server SQL Server 2008 ' den önceki sürümlerde bir süre içinde, desteklenmez.Inferring a SqlDbType from Time is not supported in versions of SQL Server earlier than SQL Server 2008. | DBTimeDBTime | SaatTime | DateTimeDateTime | |
VarNumericVarNumeric | SqlDbTypeVarNumeric arasında bir değer göstermek desteklenmez.Inferring a SqlDbType from VarNumeric is not supported. | VarNumericVarNumeric | OdbcType VarNumeric bir değer göstermek desteklenmez.Inferring an OdbcType from VarNumeric is not supported. |
SayıNumber | |
Kullanıcı tanımlı tür (içeren bir nesneSqlUserDefinedAggregateAttributeuser-defined type (an object with SqlUserDefinedAggregateAttribute | Sağlayıcıya bağlı olarak nesne veya dize (SqlClient her zaman bir nesne döndürür, ODBC her zaman bir dize döndürür ve OleDb tarafından yönetilen veri sağlayıcısı her birini görebilirObject 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 varsa SqlUserDefinedTypeAttribute , aksi takdirde varyantSqlDbType.Udt if SqlUserDefinedTypeAttribute is present, otherwise Variant | OleDbType. VarWChar (değer null ise), aksi halde OleDbType. VARIANT.OleDbType.VarWChar (if value is null) otherwise OleDbType.Variant. | OdbcType. NVarCharOdbcType.NVarChar | desteklenmiyornot supported |
Not
Ondalığa diğer türlere dönüştürme, ondalık değeri, en yakın tamsayı değerine doğru yuvarlamak için daraltma dönüştürmelerinde.Conversions from decimal to other types are narrowing conversions that round the decimal value to the nearest integer value toward zero. Dönüştürme sonucu hedef türünde gösterilemeyen bir tablo değilse, bir oluşturulur OverflowException .If the result of the conversion is not representable in the destination type, an OverflowException is thrown.
Not
Sunucuya null bir parametre değeri gönderdiğinizde, DBNull null
(Visual Basic) öğesini belirtmeniz gerekir Nothing
.When you send a null parameter value to the server, you must specify DBNull, not null
(Nothing
in Visual Basic). Sistemdeki null değeri, değeri olmayan boş bir nesnedir.The null value in the system is an empty object that has no value. DBNullnull değerleri temsil etmek için kullanılır.DBNull is used to represent null values. Veritabanı boş değerleri hakkında daha fazla bilgi için bkz. null değerlerini işleme.For more information about database nulls, see Handling Null Values.
Parametre bilgileri türetmeDeriving parameter information
Parametreler, sınıfı kullanılarak saklı bir yordamdan de türetilebilir DbCommandBuilder
.Parameters can also be derived from a stored procedure using the DbCommandBuilder
class. Hem SqlCommandBuilder
hem de OleDbCommandBuilder
sınıfları, saklı bir DeriveParameters
yordamdan parametre bilgilerini kullanan bir komut nesnesinin Parameters koleksiyonunu otomatik olarak dolduran statik bir yöntem sağlar.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. DeriveParameters
Komutuna ait varolan parametre bilgilerinin üzerine yazar.Note that DeriveParameters
overwrites any existing parameter information for the command.
Not
Parametre bilgilerini türeten, bilgilerin alınması için veri kaynağına ek bir gidiş dönüş gerektiğinden, bir performans cezası oluşur.Deriving parameter information incurs a performance penalty because it requires an additional round trip to the data source to retrieve the information. Parametre bilgileri tasarım zamanında biliniyorsa, parametreleri açıkça ayarlayarak uygulamanızın performansını artırabilirsiniz.If parameter information is known at design time, you can improve the performance of your application by setting the parameters explicitly.
Daha fazla bilgi için bkz. CommandBuilder 'lar Ile komut oluşturma.For more information, see Generating Commands with CommandBuilders.
Bir SqlCommand ve saklı yordamla parametreleri kullanmaUsing parameters with a SqlCommand and a stored procedure
Saklı yordamlar, veri odaklı uygulamalarda birçok avantaj sunar.Stored procedures offer many advantages in data-driven applications. Saklı yordamları kullanarak veritabanı işlemleri, en iyi performans için iyileştirilen ve ek güvenlikle geliştirilmiş tek bir komutta kapsüllenebilir.By using stored procedures, database operations can be encapsulated in a single command, optimized for best performance, and enhanced with additional security. Saklı yordam adının ardından parametre bağımsız değişkenleri bir SQL ifadesiyle geçirilmesiyle bir saklı yordam çağrılabilir ancak, Parameters ADO.NET nesnesinin koleksiyonunu kullanarak, DbCommand saklı yordam parametrelerini daha açık bir şekilde tanımlamanıza ve çıkış parametrelerine ve dönüş değerlerine erişebilmenize olanak sağlar.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.
Not
Parametreli deyimler, sp_executesql,
sorgu planı yeniden kullanımına izin veren kullanılarak sunucusunda yürütülür.Parameterized statements are executed on the server by using sp_executesql,
which allows for query plan reuse. Toplu işteki yerel imleçler veya değişkenler, sp_executesql
çağıran toplu işe görünür değildir sp_executesql
.Local cursors or variables in the sp_executesql
batch are not visible to the batch that calls sp_executesql
. Veritabanı bağlamındaki değişiklikler yalnızca deyimin sonuna kadar sp_executesql
.Changes in database context last only to the end of the sp_executesql
statement. Daha fazla bilgi için bkz. sp_executesql (Transact-SQL).For more information, see sp_executesql (Transact-SQL).
SqlCommandSQL Server saklı yordamı yürütmek için ile parametreleri kullanılırken, koleksiyona eklenen parametrelerin adları, Parameters saklı yordamdaki parametre işaretlerinin adlarıyla eşleşmelidir.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. SQL Server için .NET Framework Veri Sağlayıcısı, parametreleri bir SQL ifadesine veya saklı yordama geçirmek için soru işareti (?) yer tutucusunu desteklemez.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. Saklı yordamdaki parametrelere adlandırılmış parametreler olarak davranır ve eşleşen parametre işaretçilerini arar.It treats parameters in the stored procedure as named parameters and searches for matching parameter markers. Örneğin, CustOrderHist
saklı yordam adlı bir parametre kullanılarak tanımlanır @CustomerID
.For example, the CustOrderHist
stored procedure is defined by using a parameter named @CustomerID
. Kodunuz saklı yordamı yürüttüğünde, ayrıca adlı bir parametre da kullanmalıdır @CustomerID
.When your code executes the stored procedure, it must also use a parameter named @CustomerID
.
CREATE PROCEDURE dbo.CustOrderHist @CustomerID varchar(5)
ÖrnekExample
Bu örnek, örnek veritabanında SQL Server saklı yordamının nasıl çağrılacağını gösterir Northwind
.This example demonstrates how to call a SQL Server stored procedure in the Northwind
sample database. Saklı yordamın adı dbo.SalesByCategory
ve @CategoryName
veri türü olan adlı bir giriş parametresi vardır 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)
. Bu kod, SqlConnection işlem sona erdiğinde bağlantının atılabilmesi için bir using bloğu içinde yeni bir oluşturur.The code creates a new SqlConnection inside a using block so that the connection is disposed when the procedure ends. SqlCommandVe SqlParameter nesneleri oluşturulur ve özellikleri ayarlanır.The SqlCommand and SqlParameter objects are created, and their properties set. SqlDataReader, Öğesini yürütür SqlCommand
ve, çıktı, konsol penceresinde çıktıyı görüntüleyerek saklı yordamdan sonuç kümesini döndürür.A SqlDataReader executes the SqlCommand
and returns the result set from the stored procedure, displaying the output in the console window.
Not
SqlCommand
Ve nesneleri oluşturmak ve SqlParameter
ardından ayrı deyimlerde özellikleri ayarlamak yerine, tek bir deyimde birden fazla özellik ayarlamak için aşırı yüklenmiş oluşturuculardan birini kullanmayı seçebilirsiniz.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
OleDbCommand veya OdbcCommand ile parametreleri kullanmaUsing parameters with an OleDbCommand or OdbcCommand
Ya da ile parametreleri kullanırken OleDbCommand OdbcCommand , koleksiyona eklenen parametrelerin sırası, Parameters
saklı yordamınıza tanımlanan parametrelerin sırasıyla aynı olmalıdır.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. ODBC için OLE DB ve .NET Framework Veri Sağlayıcısı için .NET Framework Veri Sağlayıcısı, saklı yordamdaki parametreleri yer tutucu olarak değerlendirin ve parametre değerlerini sırasıyla uygulayın.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. Buna ek olarak, dönüş değeri parametreleri koleksiyona eklenen ilk parametre olmalıdır Parameters
.In addition, return value parameters must be the first parameters added to the Parameters
collection.
ODBC için OLE DB ve .NET Framework Veri Sağlayıcısı için .NET Framework Veri Sağlayıcısı, parametreleri bir SQL ifadesine veya saklı yordama geçirmek için adlandırılmış parametreleri desteklemez.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. Bu durumda, aşağıdaki örnekte olduğu gibi soru işareti (?) yer tutucusunu kullanmanız gerekir.In this case, you must use the question mark (?) placeholder, as in the following example.
SELECT * FROM Customers WHERE CustomerID = ?
Sonuç olarak, Parameter
nesnelerin koleksiyona eklendiği sıra Parameters
, ' nin konumuna doğrudan karşılık gelmelidir mi?As a result, the order in which Parameter
objects are added to the Parameters
collection must directly correspond to the position of the ? parametre için yer tutucu.placeholder for the parameter.
OleDb örneğiOleDb 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;
ODBC örneğiOdbc 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;