Data Search Sample
This sample demonstrates how to display a subset of data from your database.
This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.
To open the sample file in Solution Explorer
Click Download Sample.
The File Download message box appears.
Click Open, and on the left column of the zip folder window, click Extract all files.
The Extraction Wizard opens.
Click Next. You can change the directory that the files will be extracted to, and then click Next again.
Make sure that the Show extracted files check box is selected, and click Finish.
Double-click the sample's .sln file.
The sample solution is displayed in Solution Explorer. You might get a security warning that says the solution location is not trusted. Click OK to continue.
To run this sample
This sample requires the Northwind sample database. For more information, see.
Most of this form was created using the designer tools in Visual Basic. The following is a summary of how you could create this form from scratch.
To create this sample
Create a new Windows Application project.
Using the, create a connection to the Northwind database, selecting the Customers table, and saving the connection string in the application configuration file.
Open theand drag the Customers table onto the form. and controls are added to the form and configured for the Customers table.
On the smart tag for the DataGridView, click Add Query. In the dialog box, change the New Query Name to FillByLastName. In the Query Text, add WHERE LastName LIKE @lastName + '%' to the end of the Select statement. Acontrol for searching is added to the form.
Double-click NorthwindDataSet in Solution Explorer. This opens the code file NorthwindDataSet.xsd. Notice the FillByLastName method is added to the CustomersTableAdapter.