Propriedade do RDL SqlCeCommand.Parameters
Obtém a SqlCeParameterCollection.
Namespace: System.Data.SqlServerCe
Assembly: System.Data.SqlServerCe (em System.Data.SqlServerCe.dll)
Sintaxe
'Declaração
Public ReadOnly Property Parameters As SqlCeParameterCollection
Get
'Uso
Dim instance As SqlCeCommand
Dim value As SqlCeParameterCollection
value = instance.Parameters
public SqlCeParameterCollection Parameters { get; }
public:
property SqlCeParameterCollection^ Parameters {
SqlCeParameterCollection^ get ();
}
member Parameters : SqlCeParameterCollection
function get Parameters () : SqlCeParameterCollection
Valor da propriedade
Tipo: System.Data.SqlServerCe.SqlCeParameterCollection
Os parâmetros da instrução SQL. O padrão é uma coleção vazia.
Comentários
O Provedor de Dados do .NET Compact Framework para SQL Server Compact dá suporte a parâmetros nomeados para passar os parâmetros para uma instrução SQL chamada por um SqlCeCommand quando CommandType estiver definido como Text. Por exemplo:
SELECT * FROM Customers WHERE CustomerID = @customerID
Dica
Se os parâmetros na coleção não corresponderem aos requisitos da consulta a ser executada, poderá ser gerado um erro.
Exemplos
O exemplo a seguir cria um SqlCeCommand e define uma matriz de objetos 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();