Data Components in Visual Studio .NET Part3



Visual Data Components

Microsoft .NET provides many data providers to work with different types of data sources. The class hierarchy model of these data providers remains the same so programmers won't have any problem switching between data providers remains the same of these data providers are OleDb, Sql and Odbc.

If you're not sure, you can the toolbox to see if you have an Odbc data provider already installed. The toolbox's Data tab shows you the available data controls in Visual Studio. These Components are DataSet, DataView, SqlConnection, SqlCommand, SqlDataAdapter, OleDbConnection, OleDbCommand, and OleDbDataAdapter (See figure below).

toolbox.gif

Figure: Data components

With the OleDb and Sql data components, if you also see ODBC components, then you already have Odbc data provider installed. Otherwise, you have to install the Odbc data provider. After installing ODBC.NET SDK, you need go your toolbox to see the ODBC data components. After installing the ODBC.NET SDK, right-click on the toolbox and select Choose Items (see figure below).

chooseitem.gif

Figure: The Choose Items option

Now, you'll Notice a list of Component Object Model (COM) Components and .NET framework Components (see figure below). Click on the .NET framework Components tab and select the OdbcCommand, OdbcConnection, OdbcCommandBuilder, and OdbcDataAdapter components.

chooseToolBox.gif

Figure: .NET Framework Components

After clicking the OK button, use the Toolbox > Data option to see your ODBC data components (see figure below).

toolboxData.gif

Figure: Viewing your data components in the toolbox

The .NET Framework Library contains many ADO.NET data providers, including OleDb, Sql, and Odbc. The OleDb data provider wraps up native OLE-DB COM API to work with OLE-DB data source. To access an OLE-DB data source, you need to install an OLE-DB data provider for that database. Sql data providers work with SQL Server 7 or later databases. Odbc data providers wrap up the ODBC API to work with ODBC data sources (with the help of ODBC admin and ODBE drivers). You can even create your own custom data providers. Microsoft and other vendors might add more data providers, which can be added to the library later.

In the .NET framework, each of these data providers has its own namespace. For instance The System.Data.OleDb namespace consists of classes belonging to the OleDb data providers. All of these namespace classes start with OleDb. The System.Data.ODBC and System.Data.SqlClient namespaces consist of classes belonging to the Odbc and Sql data providers, respectively. Similar to OleDb, classes in Odbc start with Odbc, and classes in SqlClient start with sql.

In Visual C#, some of these classes (or objects) are available from the toolbox; you can add them to a form using drag-drop operation as any other windows control in the toolbox. These controls are data components.

All of these types of components work in pretty much the same way except for the Connection component, whose connection string will vary based on the data source to which you're connecting.

Conclusion

Hope this article would have helped you in understanding Visual Data Components. See my other articles on the website on ADO.NET.

Up Next
    Ebook Download
    View all
    Learn
    View all