Export (0) Print
Expand All

SqlCeParameter.SourceVersion Property

Gets or sets the DataRowVersion to use when loading Value.

Namespace:  System.Data.SqlServerCe
Assembly:  System.Data.SqlServerCe (in System.Data.SqlServerCe.dll)

public override DataRowVersion SourceVersion { get; set; }

Property Value

Type: System.Data.DataRowVersion
One of the DataRowVersion values. The default is Current.

Implements

IDataParameter.SourceVersion

ExceptionCondition
ArgumentException

The property was not set to one of the DataRowVersion values.

Used by UpdateCommand during an Update operation to determine whether the parameter value is set to Current or Original. This allows primary keys to be updated. This property is set to the version of the DataRow used by the Item property, or the GetChildRows method.

The following example creates a SqlCeParameter and sets the SourceVersion property.

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();
}


Show:
© 2014 Microsoft