SqlCeParameter.SourceVersion Propiedad
Obtiene o establece el DataRowVersion que se va a utilizar al cargar Value.
Espacio de nombres: System.Data.SqlServerCe
Ensamblado: System.Data.SqlServerCe (en System.Data.SqlServerCe.dll)
Sintaxis
'Declaración
Public Overrides Property SourceVersion As DataRowVersion
Get
Set
'Uso
Dim instance As SqlCeParameter
Dim value As DataRowVersion
value = instance.SourceVersion
instance.SourceVersion = value
public override DataRowVersion SourceVersion { get; set; }
public:
virtual property DataRowVersion SourceVersion {
DataRowVersion get () override;
void set (DataRowVersion value) override;
}
abstract SourceVersion : DataRowVersion with get, set
override SourceVersion : DataRowVersion with get, set
override function get SourceVersion () : DataRowVersion
override function set SourceVersion (value : DataRowVersion)
Valor de la propiedad
Tipo: System.Data.DataRowVersion
Uno de los valores del control DataRowVersion. El valor predeterminado es Current.
Implementa
Excepciones
Excepción | Condición |
---|---|
ArgumentException | La propiedad no se estableció en uno de los valores de DataRowVersion. |
Comentarios
UpdateCommand utiliza esta propiedad durante una operación Update para determinar si el valor del parámetro está establecido en Current o Original. Esto permite que se actualicen las claves principales. Esta propiedad se establece en la versión de DataRow utilizada por la propiedad Item o el método GetChildRows.
Ejemplos
En el ejemplo siguiente se crea un objeto SqlCeParameter y se establece la propiedad SourceVersion.
Dim cmd As SqlCeCommand = Nothing
Dim adp As SqlCeDataAdapter = Nothing
Try
adp = New SqlCeDataAdapter()
Dim conn As New SqlCeConnection("Data Source = MyDatabase.sdf")
' Create the SelectCommand
'
cmd = conn.CreateCommand()
cmd.CommandText = "SELECT * FROM Orders WHERE [Ship Country] = @country AND [Ship City] = @city"
cmd.Parameters.Add("@country", SqlDbType.NVarChar, 15)
cmd.Parameters.Add("@city", SqlDbType.NVarChar, 15)
cmd.Parameters("@country").Value = "UK"
cmd.Parameters("@city").Value = "London"
adp.SelectCommand = cmd
' Create the DeleteCommand
'
cmd = conn.CreateCommand()
cmd.CommandText = "DELETE FROM Orders WHERE [Order ID] = @orderID"
Dim p As SqlCeParameter = cmd.Parameters.Add("@orderID", SqlDbType.NChar, 5, "Order ID")
p.SourceVersion = DataRowVersion.Original
adp.DeleteCommand = cmd
' Populate the dataset with the results from the SELECT statement
'
Dim ds As New DataSet()
adp.Fill(ds)
' Modify the dataset
'
MessageBox.Show("Number of rows: " & ds.Tables(0).Rows.Count)
' Delete some rows
'
ds.Tables(0).Rows(3).Delete()
ds.Tables(0).Rows(4).Delete()
' This will execute two DELETE statements
'
adp.Update(ds.Tables(0))
Catch e As Exception
MessageBox.Show(e.Message)
Finally
If Not Nothing Is adp.SelectCommand Then
adp.SelectCommand.Dispose()
End If
If Not Nothing Is adp.DeleteCommand Then
adp.DeleteCommand.Dispose()
End If
End Try
SqlCeCommand cmd = null;
SqlCeDataAdapter adp = null;
try
{
adp = new SqlCeDataAdapter();
SqlCeConnection conn = new SqlCeConnection("Data Source = MyDatabase.sdf");
// Create the SelectCommand
//
cmd = conn.CreateCommand();
cmd.CommandText = "SELECT * FROM Orders WHERE [Ship Country] = @country AND [Ship City] = @city";
cmd.Parameters.Add("@country", SqlDbType.NVarChar, 15);
cmd.Parameters.Add("@city", SqlDbType.NVarChar, 15);
cmd.Parameters["@country"].Value = "UK";
cmd.Parameters["@city"].Value = "London";
adp.SelectCommand = cmd;
// Create the DeleteCommand
//
cmd = conn.CreateCommand();
cmd.CommandText = "DELETE FROM Orders WHERE [Order ID] = @orderID";
SqlCeParameter p = cmd.Parameters.Add("@orderID", SqlDbType.NChar, 5, "Order ID");
p.SourceVersion = DataRowVersion.Original;
adp.DeleteCommand = cmd;
// Populate the dataset with the results from the SELECT statement
//
DataSet ds = new DataSet();
adp.Fill(ds);
// Modify the dataset
//
MessageBox.Show("Number of rows: " + ds.Tables[0].Rows.Count);
// Delete some rows
//
ds.Tables[0].Rows[3].Delete();
ds.Tables[0].Rows[4].Delete();
// This will execute two DELETE statements
//
adp.Update(ds.Tables[0]);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
finally
{
if (null != adp.SelectCommand) adp.SelectCommand.Dispose();
if (null != adp.DeleteCommand) adp.DeleteCommand.Dispose();
}