Quick Objects Documentation Akal Tech Logo
Return Selective Fields From a Table

Glossary Item Box

Business Logic Framework - Tutorial 2:

Assuming you have a Customer class (as show in the included samples) defined that inherits from the Quick Objects Business Framework class BaseBusinessObject then you can do the following to get a DataSet of all the records in the Customers table but only the FirstName field.

1 //Business Object is created inside the Using block because it implements IDisposable interface  
2 //so in execution when block is left Dispose of object is automatically called and   
3 //it makes sure that the connections or any resources hold by the Business Object is   
4 //closed or disposed. Otherwise Database connections might be left open and that can lead to  
5 //connection pool saturation.  
6 using (Customers customer = new Customers())  
7 {  
8     // all field's visible properties will be set to false  
9     customer.UseAllFieldsForDisplay(false);  
10     // FirstName's visible property to set to true  
11     // so only first name will be included in the resulting DataTable  
12     customer.FirstName.Visible = true;  
13     this.GridView.DataSource = customer.Find();  
14     this.GridView.DataMember = customer.GetResultSetName();  
15 }  
16  
1 'Business Object is created inside the Using block because it implements IDisposable interface  
2 'so in execution when block is left Dispose of object is automatically called and   
3 'it makes sure that the connections or any resources hold by the Business Object is   
4 'closed or disposed. Otherwise Database connections might be left open and that can lead to  
5 'connection pool saturation.  
6 Using customer As Customers = New Customers()  
7     ' all field's visible properties will be set to false  
8     customer.UseAllFieldsForDisplay(False)  
9     ' FirstName's visible property to set to true  
10     ' so only first name will be included in the resulting DataTable  
11     customer.FirstName.Visible = True 
12     Me.GridView.DataSource = customer.Find()  
13     Me.GridView.DataMember = customer.GetResultSetName()  
14 End Using  
15  

Alternative method would be set each individual field's visible properties explicitly:

1 private void AlternativeMethod()  
2 {  
3     using (Customers customer = new Customers())  
4     {  
5         customer.LastName.Visible = false;  
6         customer.CustomerID.Visible = false;  
7         // FirstName's visible property to set to true  
8         // so only first name will be included in the resulting DataTable  
9         customer.FirstName.Visible = true;  
10         this.GridView.DataSource = customer.Find();  
11         this.GridView.DataMember = customer.GetResultSetName();  
12     }  
13
1 Private  Sub AlternativeMethod()  
2     Using customer = New Customers()  
3         customer.LastName.Visible = False 
4         customer.CustomerID.Visible = False 
5         ' FirstName's visible property to set to true  
6         ' so only first name will be included in the resulting DataTable  
7         customer.FirstName.Visible = True 
8         Me.GridView.DataSource = customer.Find()  
9         Me.GridView.DataMember = customer.GetResultSetName()  
10     End Using  
11 End Sub 
12  

 

 This example returns only the FirstName field and the other fields are not returned in the result set.  Every record in the table is returned.