Geography Reference
In-Depth Information
The first thing we do is make a constant string of the SQL we wish to run in the database,
and I'd like you to pay particular attention to :county in the query string. This is one of the
places where the Postgres data provider differs from the regular ADO.NET way of providing
parameters to a query string.
In regular ADO.NET code, parameters are usually prefixed with @ , e.g., @county . In
Postgres, parameters are prefixed with a : . In code, however, adding parameters is done in
the same way.
The rest is fairly self-explanatory. We open a connection using the connection string we
defined previously, open the database, add the parameter, and run our SQL before finally
getting a data reader object to read our results into a generic string list.
We're doing all of this in nested using statements, which means everything is IDisposable
and should be freed correctly once we're done, leaving us to simply return the string list of
results back to the calling method.
If everything goes according to plan, on clicking Run you should be greeted with an
application that can zoom and pan around the map defined in your database, as well as
switch to County Query Mode and retrieve a list of towns and cities in a selected county.
Your finished app should look something like the following:
Figure 84: Completed Map Application
Search WWH ::




Custom Search