Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Microsoft CSharp Programming For The Absolute Beginner (2002) [eng]-1.pdf
Скачиваний:
46
Добавлен:
16.08.2013
Размер:
15.71 Mб
Скачать

drop−down list.

Figure 11.43: You are prompted for a SELECT statement to initialize the data adapter.

The editor adds an adapter and a connection object to your form. Although these new objects are technically different objects than the SqlConnnection and SqlDataAdapter you’ve used, the OLE versions have the same properties, methods, and events. Encapsulation again saves you from worrying about how the internals of an SQL data object are different from an OLE data object.

Once you have an adapter and a connection, you can build a data set from the adapter, and attach the data set to a data grid just like you did with the SQL Server databases.

Converting a Data Set to XML

If you’ve been paying close attention, you might have noticed that every time you create a new data set Visual Studio adds a new .XSD file to your project. You might recall from Chapter 10, “Basic XML: The Quiz Maker,” that an XSD file is an XML schema. The .NET framework maintains a very close relationship between databases and XML. It’s very easy to convert between typical data and an XML file. To illustrate, I’ve added a button to the Access−XML form that displays the contacts database as an XML file. Figure 11.44 illustrates this function in action:

359

Figure 11.44: The text box displays an XML version of the Access database. The code in the View as XML button illustrates how this is done:

txtXML.Text = myDS.GetXml();

The Dataset class has a GetXml() method which extracts XML data from a data set. The resulting string can be stored as a file or be manipulated like any other XML data.

Reading from XML to a Data Source

You also can easily read an XML file and use it as a data source. If you press the Read Quiz Data button, the program loads up the quiz XML from Chapter 10 and binds it to the data grid, as shown in Figure 11.45.

360

Соседние файлы в предмете Программирование на C++