SqlCeCommand.Parameters Property
Возвращает коллекцию SqlCeParameterCollection.
Пространство имен: System.Data.SqlServerCe
Сборка: System.Data.SqlServerCe (в system.data.sqlserverce.dll)
Синтаксис
'Декларация
Public ReadOnly Property Parameters As SqlCeParameterCollection
public SqlCeParameterCollection Parameters { get; }
public:
property SqlCeParameterCollection^ Parameters {
SqlCeParameterCollection^ get ();
}
/** @property */
public SqlCeParameterCollection get_Parameters ()
public function get Parameters () : SqlCeParameterCollection
Значение свойства
Параметры инструкции SQL. Значение по умолчанию равно пустой коллекции.
Замечания
Поставщик данных .NET Compact Framework для SQL Server Compact 3.5 поддерживает именованные параметры для передачи параметров в инструкцию SQL, вызываемую объектом SqlCeCommand, если свойство CommandType имеет значение Text. Например:
SELECT * FROM Customers WHERE CustomerID = @customerID
Примечание. |
---|
Если параметры в этой коллекции не соответствуют требованиям выполняемого запроса, то может возникнуть ошибка. |
Пример
В следующем примере создается объект SqlCeCommand и определяется массив объектов SqlCeParameter.
Dim conn As New SqlCeConnection("Data Source = MyDatabase.sdf;")
conn.Open()
Dim command As SqlCeCommand = conn.CreateCommand()
' Create and prepare a SQL statement
'
command.CommandText = "INSERT INTO Region (RegionID, RegionDescription) VALUES (@id, @desc)"
Dim param As SqlCeParameter = Nothing
' NOTE:
' For optimal performance, make sure you always set the parameter
' type and the maximum size - this is especially important for non-fixed
' types such as NVARCHAR or NTEXT; In case of named parameters,
' SqlCeParameter instances do not need to be added to the collection
' in the order specified in the query; If however you use ? as parameter
' specifiers, then you do need to add the parameters in the correct order
'
param = New SqlCeParameter("@id", SqlDbType.Int)
command.Parameters.Add(param)
param = New SqlCeParameter("@desc", SqlDbType.NVarChar, 100)
command.Parameters.Add(param)
command.Parameters("@desc").Size = 100
' Calling Prepare after having set the CommandText and parameters
'
command.Prepare()
' Execute the SQL statement
'
command.ExecuteNonQuery()
' Change parameter values and call ExecuteNonQuery again
'
command.Parameters(0).Value = 21
command.Parameters(1).Value = "mySecondRegion"
command.ExecuteNonQuery()
SqlCeConnection conn = new SqlCeConnection("Data Source = MyDatabase.sdf;");
conn.Open();
SqlCeCommand command = conn.CreateCommand();
// Create and prepare a SQL statement
//
command.CommandText = "INSERT INTO Region (RegionID, RegionDescription) VALUES (@id, @desc)";
SqlCeParameter param = null;
// NOTE:
// For optimal performance, make sure you always set the parameter
// type and the maximum size - this is especially important for non-fixed
// types such as NVARCHAR or NTEXT; In case of named parameters,
// SqlCeParameter instances do not need to be added to the collection
// in the order specified in the query; If however you use ? as parameter
// specifiers, then you do need to add the parameters in the correct order
//
param = new SqlCeParameter("@id", SqlDbType.Int);
command.Parameters.Add(param);
param = new SqlCeParameter("@desc", SqlDbType.NVarChar, 100);
command.Parameters.Add(param);
command.Parameters["@desc"].Size = 100;
// Calling Prepare after having set the CommandText and parameters
//
command.Prepare();
// Execute the SQL statement
//
command.ExecuteNonQuery();
// Change parameter values and call ExecuteNonQuery again
//
command.Parameters[0].Value = 21;
command.Parameters[1].Value = "mySecondRegion";
command.ExecuteNonQuery();
Многопоточное использование
Все общие статические члены (Shared в Microsoft Visual Basic) этого типа можно использовать в многопоточных операциях. Безопасная многопоточная работа с членами экземпляров типа не гарантируется.
Платформы
Платформы разработки
Windows Vista, Windows Mobile 5.0, Windows XP Professional with Service Pack 2 (SP2), Windows Server 2003, Windows Mobile 2003 for Pocket PC, Windows CE 5.0
Сведения о версии
.NET Framework и NET Compact Framework
Поддерживается в версии 3.5
.NET Framework
Поддерживается в версии 3.0
.NET Compact Framework и .Net Framework
Поддерживается в версии 2.0
См. также
Справочник
SqlCeCommand Class
SqlCeCommand Members
System.Data.SqlServerCe Namespace
SqlCeParameter