29.5 Events Reference

FillError

 FillErrorEventHandler FillError; 

The FillError event is raised when an error is encountered during a Fill( ) operation.

Example

The following code demonstrates how to handle the FillError event:

 SqlDataAdapter da; // ... code to set up the data adapter da.FillError += new FillErrorEventHandler(da_FillError); DataSet ds = new DataSet(); da.Fill(ds); private void da_FillError(object sender, FillErrorEventArgs e); {     MessageBox.Show("RowUpdating");          // continue the Fill with the rows remaining in the data source     // despite the error     e.Continue = true; } 

Notes

The event handler receives an argument of type FillErrorEventArgs containing properties that provide specific information about the event as described in Table 29-17.

Table 29-17. FillErrorEventArgs properties

Property

Description

 Continue 

Gets or sets a value that controls whether the Fill( ) operation continues despite the error.

 DataTable 

The DataTable being filled when the error occurred.

 Errors 

The Exception being handled.

 Values 

An object array containing the values for the row being filled when the error occurred.

This information can be used to handle the event appropriately and determine if the Fill( ) operation should continue processing the DataAdapter Fill( ) operation. To continue processing, set the Continue property of the FillErrorEventArgs argument to true ; this results in the Fill( ) operation resuming with the next row in the data source.

If an error is encountered while processing the Fill( ) operation, and the FillError( ) event isn't handled, an exception is raised.

RowUpdated

 {Sql  OleDb}RowUpdatingEventHandler RowUpdating; 

The RowUpdated event is raised after the command to reconcile a row with the data source row has been executed.

Example

The following code demonstrates how to handle the RowUpdated event:

 SqlDataAdapter da; // ... code to set up the data adapter da.RowUpdated + =new SqlRowUpdatedEventHandler(da_RowUpdated); private void da_RowUpdated(object sender, SqlRowUpdatedEventArgs e); {     MessageBox.Show("RowUpdated"); } 

Notes

The event handler receives an argument of type RowUpdatedEventArgs containing properties that provide specific information about the event as described in Table 29-18.

Table 29-18. RowUpdatedEventArgs properties

Property

Description

 Command 

Gets the Command executed to perform the Update( ) .

 Errors 

Gets any errors generated by the .NET data provider when the Command executes to perform the Update( ) .

 RecordsAffected 

Gets the number of rows that deleted, changed, or inserted as a result of executing the Command .

 Row 

Gets the DataRow used in the Update( ) .

 StatementType 

Gets the type of SQL statement (DELETE, INSERT, or UPDATE) executed in the Update( ) .

 Status 

Gets or sets the UpdateStatus of the Command as described in Table 29-19.

 TableMapping 

Gets the DataTableMapping used in the Update( ) .

Table 29-19 lists and describes the values in the UpdateStatus enumeration.

Table 29-19. UpdateStatus enumeration

Value

Description

 Continue 

Continue processing rows.

 ErrorsOccurred 

Raise an error as a result of the update.

 SkipAllRemainingRows 

Do not update the current and remaining rows.

 SkipCurrentRow 

Do not update the current row and continue processing the remaining rows.

RowUpdating

 {Sql  OleDb}RowUpdatedEventHandler RowUpdated; 

The RowUpdating event is raised before the command to reconcile a row with the data source row has been executed.

Example

The following code demonstrates how to handle the RowUpdating event:

 SqlDataAdapter da; // ... code to set up the data adapter da.RowUpdating += new SqlRowUpdatingEventHandler(da_RowUpdating); private void da_RowUpdating(object sender, SqlRowUpdatingEventArgs e); {     MessageBox.Show("RowUpdating"); } 

Notes

The event handler receives an argument of type RowUpdatingEventArgs containing properties that provide specific information about the event as described in Table 29-20.

Table 29-20. RowUpdatingEventArgs

Property

Description

 Command 

Gets or sets the Command that executes to perform the update.

 Errors 

Gets any errors generated by the .NET provider when the Command executes to perform the update.

 Row 

Gets the DataRow that is used in the update.

 StatementType 

Gets the type of SQL statement (DELETE, INSERT, or UPDATE) that is executed in the update.

 Status 

Gets or sets the UpdateStatus of the Command as described in Table 29-19.

 TableMapping 

Gets the DataTableMapping that is used in the update.



ADO. NET in a Nutshell
ADO.NET in a Nutshell
ISBN: 0596003617
EAN: 2147483647
Year: 2005
Pages: 415

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net