interactive | editorial | code | resource 
Demonstrations > Airports demo
 

Airports demo

Directory of airports

This database of airports contains over 900 records. DbCombo provides a convenient method of finding the required record. The query is configured to perform a full substring search on the text, so typing "London" returns all five London airports, despite none of the displayed names start with the word "London".

    

The code...

And the code required to produce this functionality? - take a look:

<DbCombo:DbCombo Runat=server ID="Dbcombo1" DropDownRows="20" />

<script runat=server>
    [Cambro.Web.DbCombo.ResultsMethod(true)]
    public static object DbComboMethod(
        Cambro.Web.DbCombo.ServerMethodArgs args)
    {
    
        SqlConnection conn = new SqlConnection("your-connection-string");
        
        SqlCommand myCommand = new SqlCommand(@"
            SELECT TOP "+args.Top+" 
            AirportName, 
            AirportName+', '+
                AirportCity+', '+
                AirportCountry+' ('+
                AirportFourLetterCode+')' AS DbComboText, 
            AirportFourLetterCode AS DbComboValue 
        FROM Airport 
        WHERE AirportName+', '+
            AirportCity+', '+
            AirportCountry+' ('+
            AirportFourLetterCode+')' LIKE @Query 
        ORDER BY AirportName", conn);
            
        myCommand.Parameters.Add("@Query", "%"+args.Query+"%");
        
        myCommand.Connection.Open();
        
        return myCommand.ExecuteReader(CommandBehavior.CloseConnection);
    }
</script>

 
Demonstrations > Airports demo