Review Questions


1:

When using the Data Adapter Wizard, what property must be configured first and why?

A1:

The data provider needs to be set first, even though the wizard shows the Connection tab first. The reason the wizard does this is because it defaults to Microsoft SQL Server as the data provider. You need to make sure that default is acceptable or, if not, click on the Provider tab and select the correct database provider. This is important because the content of the Connection tab differs according to the database provider selected.

2:

When the Data Adapter Wizard finishes its job, where is the code written that is associated with the answers you supplied to the wizard?

A2:

The code appears in the region named Windows Form Designer generated code . The code that appears in that region provides the details necessary for Visual Basic .NET to establish a connection to the database.

3:

What is the purpose of the Query Builder?

A3:

As the name suggests, the Query Builder is used to construct an SQL query of the database. Once again, however, you can use the SQL statements you learned in Chapter 24 to construct your own queries without using the Query Builder.

4:

What is the purpose of the DataSet object?

A4:

The DataSet object holds the results of any queries that are made on the database. After a query on the database is completed and assuming no errors, the DataSet object will contain the records that meet the conditions stated in the query.

5:

If you want to write a connect string without using a wizard, how should the string be constructed ?

A5:

The exact nature of the string depends on the database to which you want to connect. If we assume the Microsoft Access database is being used, the connect string might be written

 strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User _          ID=Admin;Data Source=" 

Notice that we haven't filled in the Data Source parameter yet. This is normally done after the OpenFileDialog dialog box has returned the name of the database. After OpenFileDialog has finished, and assuming that a variable named FileName holds the path and name of the database, the connect string can be completed with

 strConnect &= FileName 

You can now use strConnect with the Open () method.

6:

What is a serious limitation of the current implementation of ADO.NET?

A6:

At the present time, ADO.NET does not implement a data definition language. The DDL is used to create your own databases. As a result, if you want to create a new database on your own, you need to use one of the wizards supplied with Visual Studio or construct the database with the database management (DBM) tools provided with the database. (One of the reasons I elected to use Microsoft's Access database in my examples is because most Windows systems are shipped with Microsoft Office, which contains Access.) Microsoft promises to have the DDL done "real soon now."

7:

Assuming that you've built the connect string in strConnect , SQL holds the query string, and MyTable is the table name, what statements are necessary to read the database and retrieve a recordset?

A7:

You would need to code:

 Dim MyConnect As New OleDbConnection(strConnect)  MyConnect.Open()           ' ...and reopen the connection Dim MyAdapter As New OleDbDataAdapter(SQL, MyConnect) Dim MyDataSet As New DataSet() Try  RecordsRead = MyAdapter.Fill(MyDataSet, 0, MAX_RECORDS, MyTable) Catch  MessageBox.Show("Check the SQL query syntax for possible errors.") End Try 
8:

The code you wrote for question number 7 filled in a DataSet object with records from the database. Assuming you have a bound DataGrid control named MyGrid , what statements must be written to display the recordset data?

A8:

A single statement will suffice:

 MyGrid.SetDataBinding(MyDataSet, MyTable) 
9:

Suppose that you have a text box named txtLastName that you want to bind to the LastName field of the Customer table. What statement will accomplish this?

A9:

The statement is

 txtLastName.DataBindings.Add("Text", MyDataSet, "Customer.LastName") 

The first argument states the data type for the field, the second is the data set that holds the data, and the final argument is the table and field name under consideration.

10:

What statement would you use to delete a record from a database?

A10:

This is a trick question. You probably shouldn't delete a record from the database. A better way is to implement a Status field for each record. Set the record to 1 when it's created. If you decide at some later time that you can delete it, simply change the Status to . If you use a WHERE predicate that tests for Status , you can return datasets where only the active data are returned. In similar fashion, you could build a query string that would return only the dead data, too!



Visual Basic .NET. Primer Plus
Visual Basic .NET Primer Plus
ISBN: 0672324857
EAN: 2147483647
Year: 2003
Pages: 238
Authors: Jack Purdum

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net