Computed Values
Get Largest Field Value from a Table Column

Description
This customization shows how to get the largest field value from a table column.
Variables
Table Name
Select a database table with numeric field(s)
Numeric Field
Select a numeric field in the table
Applies to
DataAccessClass class
Code
 
/// 
/// This function gets the largest field value.
/// 
public int GetLargest() 
{ 

    // Create where string 
    // example of where clause is
    // whereStr = " myNumericField = 1"; 
    // whereStr = " myStrField = '1'";
    string whereStr = "";

    // Create the order by object.
    bool bExpandForeignKeyColumns = false;
    bool bIsCaseInsensitive = false;
    BaseClasses.Data.OrderBy oB = new OrderBy(bExpandForeignKeyColumns, bIsCaseInsensitive);
    oB.AddColumn(this.${Numeric Field}Column, BaseClasses.Data.OrderByItem.OrderDir.Desc);

    // Get the record.
    ${${Table Name}RecordClassName} rec = ${${Table Name}ClassName}.GetRecord(whereStr, oB);
	
	if (!(rec==null)){
		// Return the largest field value.
		return Int32.Parse(rec.${Numeric Field}.ToString());
	}
	 
	// If no records are available in the table, then return zero. 
	return -1;
}

     


  Privacy Statement