ADO.NET Data Filtering
Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013
This lesson describes how to filter data in ADO.NET
Filtering data is a very important part of ADO.NET, because usually you don't need all the data from a table. Rather, you need only a fraction of the rows from a table at any given time.
For example, an e-commerce application that shows the order history will often need to display the orders for only one customer at a time. So there could be millions of orders in the database, but the user of the software will view only a handful of rows instead of the entire table.
In order to filter the rows returned from a query, you will need to add a WHERE clause to your SELECT statement.
The WHERE clause is processed as second by the database engine, right after the FROM clause, and contains expressions, called predicates that are evaluated to TRUE, FALSE and UNKNOWN.
The WHERE clause syntax is as follows:
SELECT [column1] FROM [table1] WHERE [column] = [value];
The following examples demonstrate how to compare a column to a literal value. Pleaes notice that tick marks, or single quotes, have been used around literal strings or dates.
SELECT * FROM Orders WHERE OrderDate = '2014-12-12';
SELECT * FROM Orders WHERE IPAddress = '192.168.0.1';
Unlike the previous example, this example demonstrate how to compare a column to a numeric value, and for that you don't need to use the single quotes.
SELECT * FROM Orders WHERE UserID = 9211;