Workshop

for RuBoard

This workshop will help reinforce the concepts covered in today's lesson.

Quiz

1:

How can you obtain the ODBC .NET Data Provider?

A1:

The Odbc provider doesn't ship with VS .NET, so you must go to msdn.microsoft.com and download it. After it is downloaded, it will install into the Global Assembly Cache (GAC) and can be referenced in your projects using the Add References dialog.

2:

What kinds of connections can you use with the Odbc provider?

A2:

Just as traditionally done, you can use either a user or system DSN specified by the DSN attribute, a file DSN specified with the FileDSN attribute, or a DSN-less connection string that specifies the driver and any driver-specific attributes.

3:

What is the advantage to implementing a data reader class in your provider?

A3:

If you implement both a command and a data reader class (that implements the IDataReader interface), you can also implement a data adapter class with virtually no work at all. This is possible because you can derive from the DbDataAdapter class, which calls the ExecuteReader method behind the scenes.

4:

What is the primary reason to implement a .NET Data Provider?

A4:

The most common reason to implement a provider is to provide managed access to a proprietary data store. This makes a great deal of sense for organizations that produce packaged software and want to start developing .NET applications.

Exercise

Q1:

To illustrate the side-by-side use of providers, write a method that uses the SqlClient provider to populate a DataSet with Titles and use the Odbc provider to populate a second table in the same DataSet with Publishers .

A1:

One possible solution to the exercise follows :

 public virtual DataSet PopulateTitles(string connect) {     SqlConnection scon = new SqlConnection(connect);     SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM Titles",scon);     OdbcConnection ocon = new OdbcConnection("Driver={SQL Server} ;" + connect);     OdbcDataAdapter oda = new OdbcDataAdapter("SELECT * FROM Publishers",ocon);     DataSet ds = new DataSet();     // Fill from SqlClient     sda.MissingSchemaAction = MissingSchemaAction.AddWithKey;     sda.Fill(ds);     // Fill from Odbc     oda.MissingSchemaAction = MissingSchemaAction.AddWithKey;     oda.Fill(ds);     // Add a relationship     ds.Relations.Add(ds.Tables[1].Columns["PubCode"],       ds.Tables[1].Columns["Publisher"]);     return ds; } 

Note that a DSN-less ODBC connection string can be built simply by prefixing the one used for SqlClient.

for RuBoard


Sams Teach Yourself Ado. Net in 21 Days
Sams Teach Yourself ADO.NET in 21 Days
ISBN: 0672323869
EAN: 2147483647
Year: 2002
Pages: 158
Authors: Dan Fox

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