Occurs during Update after a command is executed against the data source. The attempt to update is made, so the event fires.
[Visual Basic] Public Event RowUpdated As SqlCeRowUpdatedEventHandler [C#] public event SqlCeRowUpdatedEventHandler RowUpdated; [C++] public: __event SqlCeRowUpdatedEventHandler* RowUpdated;
[JScript] In JScript, you can handle the events defined by a class, but you cannot define your own.
The event handler receives an argument of type SqlCeRowUpdatedEventArgs containing data related to this event. The following SqlCeRowUpdatedEventArgs properties provide information specific to this event.
| Property | Description |
|---|---|
| Command | Gets the SqlCeCommand executed when Update is called. |
| Errors (inherited from RowUpdatedEventArgs) | Gets any errors generated by the .NET Framework data provider when the Command was executed. |
| RecordsAffected (inherited from RowUpdatedEventArgs) | Gets the number of rows changed, inserted, or deleted by execution of the SQL statement. |
| Row (inherited from RowUpdatedEventArgs) | Gets the DataRow sent through an Update. |
| StatementType (inherited from RowUpdatedEventArgs) | Gets the type of SQL statement executed. |
| Status (inherited from RowUpdatedEventArgs) | Gets the UpdateStatus of the Command property. |
| TableMapping (inherited from RowUpdatedEventArgs) | Gets the DataTableMapping sent through an Update. |
When using Update, there are two events that occur for each data row updated. The order of execution is as follows:
[Visual Basic, C#] The following example shows the RowUpdating and RowUpdated events in use.
[Visual Basic] ' handler for RowUpdating event Protected Shared Sub OnRowUpdating(ByVal sender As Object, ByVal e As SqlCeRowUpdatingEventArgs) PrintEventArgs(e) End Sub 'OnRowUpdating ' handler for RowUpdated event Protected Shared Sub OnRowUpdated(ByVal sender As Object, ByVal e As SqlCeRowUpdatedEventArgs) PrintEventArgs(e) End Sub 'OnRowUpdated Public Overloads Shared Function Main(ByVal args() As String) As Integer Const CONNECTION_STRING As String = "Data Source = nwind.sdf" Const SELECT_ALL As String = "select * from Products" ' create DataAdapter Dim rAdapter As New SqlCeDataAdapter(SELECT_ALL, CONNECTION_STRING) Dim cb As SqlCeCommandBuilder = New SqlCeCommandBuilder(rAdapter) ' Create and fill dataset (select only first 5 rows) Dim rDataSet As New DataSet() rAdapter.Fill(rDataSet, 0, 5, "Table") ' Modify dataSet Dim rTable As DataTable = rDataSet.Tables("Table") rTable.Rows(0)(1) = "new product" ' add handlers AddHandler rAdapter.RowUpdating, AddressOf OnRowUpdating AddHandler rAdapter.RowUpdated, AddressOf OnRowUpdated ' update, this operation fires two events (RowUpdating/RowUpdated) per changed row rAdapter.Update(rDataSet, "Table") ' remove handlers RemoveHandler rAdapter.RowUpdating, AddressOf OnRowUpdating RemoveHandler rAdapter.RowUpdated, AddressOf OnRowUpdated Return 0 End Function 'Main Protected Overloads Shared Sub PrintEventArgs(ByVal args As SqlCeRowUpdatingEventArgs) Console.WriteLine("OnRowUpdating") Console.WriteLine(" event args: (" & " command=" & args.Command.CommandText & _ " commandType=" & args.StatementType & " status=" & args.Status & ")") End Sub 'PrintEventArgs Protected Overloads Shared Sub PrintEventArgs(ByVal args As SqlCeRowUpdatedEventArgs) Console.WriteLine("OnRowUpdated") Console.WriteLine(" event args: (" & " command=" & args.Command.CommandText & _ " commandType=" & args.StatementType & " recordsAffected=" & _ args.RecordsAffected & " status=" & args.Status & ")") End Sub 'PrintEventArgs End Class 'Form1 [C#] // handler for RowUpdating event protected static void OnRowUpdating(object sender, SqlCeRowUpdatingEventArgs e) { PrintEventArgs(e); } // handler for RowUpdated event protected static void OnRowUpdated(object sender, SqlCeRowUpdatedEventArgs e) { PrintEventArgs(e); } public static int Main(String[] args) { const string CONNECTION_STRING = "Data Source = nwind.sdf"; const string SELECT_ALL = "select * from Products"; // create DataAdapter SqlCeDataAdapter rAdapter = new SqlCeDataAdapter(SELECT_ALL, CONNECTION_STRING); SqlCeCommandBuilder cb = new SqlCeCommandBuilder(rAdapter); // Create and fill dataset (select only first 5 rows) DataSet rDataSet = new DataSet(); rAdapter.Fill(rDataSet, 0, 5, "Table"); // Modify dataSet DataTable rTable = rDataSet.Tables["Table"]; rTable.Rows[0][1] = "new product"; // add handlers rAdapter.RowUpdating += new SqlCeRowUpdatingEventHandler( OnRowUpdating ); rAdapter.RowUpdated += new SqlCeRowUpdatedEventHandler( OnRowUpdated ); // update, this operation fires two events (RowUpdating/RowUpdated) per changed row rAdapter.Update(rDataSet, "Table"); // remove handlers rAdapter.RowUpdating -= new SqlCeRowUpdatingEventHandler( OnRowUpdating ); rAdapter.RowUpdated -= new SqlCeRowUpdatedEventHandler( OnRowUpdated ); return 0; } protected static void PrintEventArgs(SqlCeRowUpdatingEventArgs args) { Console.WriteLine("OnRowUpdating"); Console.WriteLine(" event args: ("+ " command=" + args.Command + " commandType=" + args.StatementType + " status=" + args.Status + ")"); } protected static void PrintEventArgs(SqlCeRowUpdatedEventArgs args) { Console.WriteLine("OnRowUpdated"); Console.WriteLine( " event args: ("+ " command=" + args.Command + " commandType=" + args.StatementType + " recordsAffected=" + args.RecordsAffected + " status=" + args.Status + ")" ); }
[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button
in the upper-left corner of the page.
.NET Framework Security:
SqlCeDataAdapter Class | SqlCeDataAdapter Members | System.Data.SqlServerCe Namespace