Quick Objects Documentation Akal Tech Logo
Update Multiple Records

Glossary Item Box

Business Logic Framework - How To:

Updating multiple records of a single table at a time is very simple task with Quick Objects. The process is similar to specifying a search criteria for Find method and specifying what needs to be saved during an Update method.  Once the search criteria is specified and the values that need to be updated are set it is as simple as calling the BulkUpdate method. The BulkUpdate method returns a bool if there were any records updated. A false return doesn't not mean that there were any errors, to check for errors please use the ErrorString property.  After the BulkUpdate method has executed, you can use the AffectedRecords property to get a total number of rows updated by the statement.

 Note: We recommend that you use caution while using BulkUpdate and BulkDelete methods as they can modify/delete many records at a time, and if wrong criteria is specified by mistake the result can be disastrous.

The target of the following code is to update all the UserRoles records where the RoleName value is "Client". Since the RoleName column is in the Roles table, we will create a join between UserRoles and Roles objects and set the UseInSave and UseInSearch properties of the appropriate fields that we would like to include in our search criteria and the ones that need to be updated.

1 using (UserRoles ur = new UserRoles())  
2 {  
3     ur.Join_RoleID_Roles_Parent();  
4     // We can specify search criteria on joined objects.  
5     // In the following two lines we will assign the value "Client" to the RoleName and also set RoleName's UseInSearch property to true.  
6     ur.RoleID_Roles_Parent.RoleName.Value = "Client";  
7     ur.RoleID_Roles_Parent.RoleName.UseInSearch = true;  
8  
9     // Our target is to set the IsActive to true (and 'Y' for Oracle) so we set the IsActive value to true, and set the IsActive's UseInSave property to true as well.  
10     ur.IsActive.Value = true;  
11     ur.IsActive.UseInSave = true;  
12  
13     // BulkUpdate method uses the search criteria and creates an update statement capable of updating 0-n records based on your criteria and available records in the database.  
14     // If there is an error during the update process the method will return false.  
15     if (ur.BulkUpdate())  
16     {  
17         MessageBox.Show(ur.AffectedRecords.ToString() + " records updated");  
18     }  
19     else 
20     {  
21         MessageBox.Show("Records could not be updated. Error: " + ur.ErrorString);  
22     }  
23 }  
24  
1 Using ur As UserRoles = New UserRoles()  
2     ur.Join_RoleID_Roles_Parent()  
3     'We can specify search criteria on joined objects.  
4     'In the following two lines we will assign the value "Client" to the RoleName and also set RoleName's UseInSearch property to true.  
5     ur.RoleID_Roles_Parent.RoleName.Value = "Client" 
6     ur.RoleID_Roles_Parent.RoleName.UseInSearch = True 
7  
8     'Our target is to set the IsActive to true (and 'Y' for Oracle) so we set the IsActive value to true, and set the IsActive's UseInSave property to true as well.  
9     ur.IsActive.Value = True 
10     ur.IsActive.UseInSave = True 
11       
12     'BulkUpdate method uses the search criteria and creates an update statement capable of updating 0-n records based on your criteria and available records in the database.     
13     'If there is an error during the update process the method will return false.  
14     If ur.BulkUpdate() Then 
15         MessageBox.Show(ur.AffectedRecords.ToString() & " records updated")  
16     Else 
17         MessageBox.Show("Records could not be updated. Error: " & ur.ErrorString)  
18     End If 
19 End Using  
20  

See Also:

BulkUpdate Method