0% found this document useful (0 votes)
46 views43 pages

Test Prep

The document discusses how to add SQL queries to a table adapter in a .NET dataset. It describes adding two queries: one to sort data by price descending and another to filter rows with over 200 units. Buttons are added to execute each query and their click event handlers are written.

Uploaded by

Mhlengi Wiseman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views43 pages

Test Prep

The document discusses how to add SQL queries to a table adapter in a .NET dataset. It describes adding two queries: one to sort data by price descending and another to filter rows with over 200 units. Buttons are added to execute each query and their click event handlers are written.

Uploaded by

Mhlengi Wiseman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 43

MP lecture

TEST PREP
• posProductsTableAdapter – gets data directly from the data source.
• tableAdapterManager – manages multiple tables in the database.
• posProductDataSet – gets a copy of the table from the table adapter
and keeps it in memory. The application works with the dataset
instead of working directly with the database. Instructs the table
adapter to write changes back to the database.
• posProductsBindingSource – is a component that can connect user
interface controls directly to the dataset.
Table Adapter Queries

• A table adapter query is an SQL statement that is stored in a table


adapter and can be executed simply by calling a method.
• For example, a table adapter contains a query that fills a dataset with
data from a table. The query can be executed by calling the table
adapter’s FILL method.
• In the Solution Explorer, look for the Schema Definition File that
describes the contents of the PosProductsDataSet. The file appears as
PosProductsDataSet.xsd in Solution Explorer.
• Double click PosProductsDataSet.xsd to open it in an editor window.
The area at the top of the editor window shows the columns that are included in the dataset.
The area at the bottom shows the table adapter query methods.
Right-click the area that reads Fill, GetData ( )
Right-click the area that reads Fill, GetData ( )
Select Configure from the pop-up menu
Note the SQL query that appears in TableAdapter Configuration Wizard window.
The dataset is filled with the rows that are returned by the SELECT statement.
If you were to modify the query, for example, adding WHERE clause, and clicking finish button, the data that is initially displayed in the
DataGridView would change accordingly.
Click Cancel button to close.
Creating PosProduct (my table name) Queries
Application
• We created an application that displays the PosProducts table from
our database in a DataGridView control.
• We want to add two SQL queries to the table adapter:
- A query to return all the rows sorted by price in descending
order.
- A query to return all the rows with more than 200 units.
• Add buttons on the application form that executes the queries.
In the Solution Explorer, double-click the PosProducts.xsd to open the dataset schema description.
Right-click the area that reads PosProductsTableAdapter.
Click on Add Query
The Table Adapter query configuration wizard appears.
Make sure Use SQL statements is selected, and click Next
The wizard prompts you to choose a query type.
SELECT which returns rows is selected, click Next>
Add Order By Price Desc clause to the end of the statement, Click Next>
The wizard prompt you to Choose Methods to Generate.
We are interested only in generating a method to fill the dataset with the results of our SQL statement.
- Make sure Fill a DataTable is checked.
- Under Fill a DataTable, enter FillByPrice as the method name. This will be the name of the method that executes the SQL statement
- Make sure Return a DataTable is not checked
Click Next>
The wizard shows the results of the configuration.
Click Finish button.
Notice: The Schema definition (PosProductsDataSet.xsd) now has FillByPrice ( ) at the butom of the diagram
Next you add the second query that returns rows with units greater than 200.
Repeat the same process
- Right-click PosProductsTableAdapter
- Select Add and click Query
Add Where Quantity > 200
Modify Method name to FillByQuantity
Notice the FillByQuantity in the Schema Definition file
Add Button controls for the query
Click on Sort By Price and write the event handler
Click Product Quantity > 200 and write the event handler
Line 37: Event handler for sortByPriceButton_Click event
Line 42: Event handler for quantityGreater200_Click event
END

You might also like