SqlCommand.Parameters Özellik
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
alır SqlParameterCollection .
public:
property Microsoft::Data::SqlClient::SqlParameterCollection ^ Parameters { Microsoft::Data::SqlClient::SqlParameterCollection ^ get(); };
public Microsoft.Data.SqlClient.SqlParameterCollection Parameters { get; }
member this.Parameters : Microsoft.Data.SqlClient.SqlParameterCollection
Public ReadOnly Property Parameters As SqlParameterCollection
Özellik Değeri
Transact-SQL deyiminin veya saklı yordamın parametreleri. Varsayılan değer boş bir topluluktur.
Örnekler
Aşağıdaki örnekte, ' SqlCommand nin nasıl oluşturulacağı ve parametresinin nasıl ekleneceği gösterilmektedir SqlParameterCollection.
using System;
using System.Data;
using Microsoft.Data.SqlClient;
class Program
{
static void Main()
{
string connectionString = GetConnectionString();
string demo = @"<StoreSurvey xmlns=""http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/StoreSurvey""><AnnualSales>1500000</AnnualSales><AnnualRevenue>150000</AnnualRevenue><BankName>Primary International</BankName><BusinessType>OS</BusinessType><YearOpened>1974</YearOpened><Specialty>Road</Specialty><SquareFeet>38000</SquareFeet><Brands>3</Brands><Internet>DSL</Internet><NumberEmployees>40</NumberEmployees></StoreSurvey>";
Int32 id = 3;
UpdateDemographics(id, demo, connectionString);
Console.ReadLine();
}
private static void UpdateDemographics(Int32 customerID,
string demoXml, string connectionString)
{
// Update the demographics for a store, which is stored
// in an xml column.
string commandText = "UPDATE Sales.Store SET Demographics = @demographics "
+ "WHERE CustomerID = @ID;";
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(commandText, connection);
command.Parameters.Add("@ID", SqlDbType.Int);
command.Parameters["@ID"].Value = customerID;
// Use AddWithValue to assign Demographics.
// SQL Server will implicitly convert strings into XML.
command.Parameters.AddWithValue("@demographics", demoXml);
try
{
connection.Open();
Int32 rowsAffected = command.ExecuteNonQuery();
Console.WriteLine("RowsAffected: {0}", rowsAffected);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
Açıklamalar
SQL Server için Microsoft .NET Framework Veri Sağlayıcısı, parametreleri bir SQL Deyimine veya komutu tarafından çağrılan saklı yordama geçirmek için soru işareti (?) yer tutucusunu CommandType.Textdesteklemez. Bu durumda adlandırılmış parametreler kullanılmalıdır. Örnek:
SELECT * FROM Customers WHERE CustomerID = @CustomerID
Not
Koleksiyondaki parametreler yürütülecek sorgunun gereksinimleriyle eşleşmiyorsa bir hata oluşabilir.
Daha fazla bilgi için bkz . Parametreleri yapılandırma.