1. Home
  2. Computing & Technology
  3. Visual Basic
Using ADO .NET - Changing Databases - Part 4
2 - Selecting Part Of The Database
 More of this Feature
• 1 - When Something Has To Change!
• 3 - Binding and Changes
• 4 - The Code and Download
 
 Join the Discussion
Is this the kind of article that helps you?
Let us know!
 
 Related Resources
• Part 1 of the ADO .NET Series
• Part 2 of the ADO .NET Series
• Part 3 of the ADO .NET Series
• VB .NET Books!
• New to VB .NET?
  Learn It Here!
 
 Elsewhere on the Web
• About.Com DATABASES
 

Open the project we completed in Part 3 and display the Form object in Design mode. Notice the OleDbSelectCommand1 component that the wizard added beneath the Form display. (Default names generated by the wizard were used in this example, but like other components, you can choose your own names when you create them.) There are several ways to add or change a SQL statement. One is to just click the text in the properties dialog and change it directly. Another is to open the Properties and click the ellipsis (the three dots at the right side) for CommandText.

This gives you a Query Builder dialog where you can change the Select statement.

Query Builder

Or, another way is to change the DataAdapter by executing the wizard again by clicking Configure DataAdapter on the context menu (right-click OleDbDataAdapter1 to display the context menu) and enter a new SQL statement at the appropriate place in the wizard. (See Part 3 for more detailed instructions on this wizard.) We're going to do it this way because we also want to add change instructions using the wizard.

When you reach the Generate the SQL Instructions panel in the wizard, add this text to the end: WHERE (artTitle LIKE ? + '%'). The entire SQL Statement should now read:

SELECT artDate, artDescription, artKey, artTitle, artURL, artVB6, artVBNET FROM Articles WHERE (artTitle LIKE ? + '%')

The "?" in the WHERE clause is a parameter that is replaced by an actual value when the SQL is executed. We'll do more with that in just a little while. Note that the way you code this in Access and SQL Server is quite different. With SQL Server, you would use something that looks like: @parTitle rather than a question mark.

When the wizard has completed, modify your program by adding this statement above statement that executes the Fill method for the DataAdapter:

Me.OleDbDataAdapter1.SelectCommand.Parameters(0).Value = "VBA"

Now run the program again. This time only the titles starting with VBA are selected. These are the About Visual Basic VBA Tutorial Series articles. Since finding the correct properties to change is the key to doing things right, notice that the names of properties in the program, such as SelectCommand above, are the same ones that you saw when you opened the properties window for the DataAdapter component. The zero index parameter is the one (actually, the only one in this simple example) referenced by the question mark in the SQL statement.

Selected Result

Next page > Binding and Changes > Page 1, 2, 3, 4

Explore Visual Basic
By Category
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Visual Basic

©2009 About.com, a part of The New York Times Company.

All rights reserved.