tailieunhanh - GetErrors Products DataTable
The first statement extracts the Products DataTable in the changes DataSet. The GetErrors method of a DataTable object returns an array of all the rows in the table that have one or more validation errors. If there are no errors, GetErrors returns an empty array. 1. Replace the // If no errors then update the database, otherwise tell the user comment with the following code block: 2. if ( == 0) 3. { 4. // Update the database 5. } 6. else 7 | The first statement extracts the Products DataTable in the changes DataSet. The GetErrors method of a DataTable object returns an array of all the rows in the table that have one or more validation errors. If there are no errors GetErrors returns an empty array. 1. Replace the If no errors then update the database otherwise tell the user comment with the following code block 2. if 0 3. 4. Update the database 5. 6. else 7. 8. Find the errors and inform the user There are several strategies you can use for reporting errors to the user. One useful technique is to find all the errors and report them in a single but possibly long message. 9. Replace the Find the errors and inform the user comment with the following statements 10. string errorMsg null 11. foreach DataRow row in badRows 12. 13. foreach DataColumn col in 14. 15. errorMsg col n 16. 17. 18. Errors in data errorMsg 19. Please fix This code iterates through all the rows in the badRows array. Each row may have one or more errors and the GetColumnsInError method returns a collection containing all the columns with bad data. The GetColumnError method retrieves the error message for an individual column. Each error message is appended to the errorMsg string. When all the bad rows and columns have been examined the application displays a message box showing all the errors. The user should be able to use this information to correct the changes and then resubmit them. Integrity Rules and DataSets In this example which uses a simple single table DataSet you are unlikely to get any validation errors reported by GetErrors. When the northwindDataSet class was generated it also included information about primary key columns data types for each column integrity rules and so on obtained from the database. A user typically makes changes to rows by using objects such as the DataGridView control which has its own .
đang nạp các trang xem trước