Searching Your Database Lesson 10 Searching Your Database
Dynamic Searches via a web page Searching a database is quite common when using a database The Code Builders once again will be used to create the necessary code you’ll need to make this happen Create a new ASP.Net file and call it FindActress
Select Code Builder Click on Code Left Click over Select Data Method and drag it over your workspace Click the down arrow to the right of Database: Select the Movies Database, click Ok
Construct A Select Query Click on the following: MovieName Actress Director
Where Clause Builder Click on Actress Locate Operator- Click the down arrow and select like Locate Filter- Type @search Click Ok
Here’s what you have
Test Query Click Next Click Test Query Type Jill St. John Does the Query work?
Creating A Method Type FindByActress to create this method Click Finish
Using FindByActress Method Click on Design View Type Bond Actresses on the workspace Drag a TextBox from the Web Control Toolbox and place it to the right of Bond Actresses Drag a button and place it to the right of your TextBox Drag a DataGrid and place it on the workspace Click on Layout from the Menu Bar and click on Absolute Position and move the DataGrid to the middle of your workspace
Finished Design View
Tying It All Together Double click the button to create a Click event This code will use the FindByActress method that was created so that when you click the button the user will type in the Bond Actress and the Movies Database will then locate that record and create the table on the web page
Type the code in white Sub Button1_Click(sender As Object, e As EventArgs) Dim sActress As String = TextBox1.Text DataGrid1.DataSource = FindByActress(sActress) DataGrid1.DataBind() End Sub
Read To Test? Click Save to save the file Press F5 and load the browser software to view Type Jill St. John in the Textbox and click the button
Modifying The Web Page Your page looks kind of boring so let’s dress it up with some changes. Click on the DataGrid Go to AutoFormat which is below the Property on the right bottom Select Colorful5 Change the Font to Georgia and the size to 5
More changes Highlight Find Actresses and change the font size to 5 and Go to Format and change the Foreground color to Red Click the button and look at the Properties Change the Fore Color to red and the Back Color to yellow Change the Text to Go Press F5 to see your changes
Change the colors if you don’t like them