Working with OLE DB Adapter

Source: Internet
Author: User
Tags ole visual studio

submitted by User Level Date of submissionMahesh chandbeginners06/19/2001
Platform Used:VS.NET Beta 2 (Test build)
Description of the Article:
Microsoft Visual Studio. NET (vs.net afterwards) is full with data-bound controls and wizards. These controls and wizards help you to generate your applications. You just set some properties of this controls and use wizards to generate code. In couple of minutes, for you develop a full-fledged working application.
In this series of articles, my I-article is OLE DB Data Adapter Controls in Vs.net. In this article, I'll show you the How to display data in a DataGrid control by writing only one line of code. You just follow this simple steps:
Step 1:create Project
Pick Visual c#->windows Application project and type your project name and Pick a directory.

Step 2:add OLE DB Data Adapter
Drag an OleDbDataAdapter control from Toolbox->data to your form. Data Adapter Configuration Wizard appears and it guides you towards to create your Data Adapter pbject.
The wizard.

Second screen would let you create a connection. If you are already have connections, they are available in a drop down list. You are either pick a connection from your list or create a new connection.

Next page provides your options to use SQL statements or stored procedures.

Next step is to generate SQL statement. Use the query Builder button to build a query.

This option let you pick your database tables.

And now you are pick what columns you want to get data from the database to the DataAdapter.

This page shows for you your SQL Statement. Can even write SQL statement by yourself (with no help Query Builder).

Last page shows your Activities wizard finished.

Step 3:generate DataSet
Next are to generate datasets and connect datasets to a DataView component. Generate a DataSet by using the "Generate DataSet" option in DataAdapter ' s Properties dialog-

Generate DataSet link shows you dataset. Pick "New" option and type your DataSet name. You can pick as many as tables your want from the list.

By clicking "OK" button, Wizard generates a dataset and shows your IT ' s properties dialog. You can change the DataSet name and other properties. "View Schema" option shows the XML schema for this dataset added by the wizard and "DataSet Properties" option shows Y Ou the properties.

This action adds one DataSet derived class to your project. We ' re not going in to details of this class.

Step 4:attach DataSet with a DataView
Now attach the this dataset with a DataView. Drag a DataView control from Toolbox->data and set it's table to your DataSet ' s table.

Step 5:attach DataView with the DataGrid control and Fill the DataSet
Now drag A's DataGrid control is toolbox->winfroms to the form and the set's DataSource property to DataView.

Now fill the "Data from DataAdapter to" DataSet by calling DataAdapter ' s fill method. I write this code after InitializeComponent ();
InitializeComponent ();
Oledbdataadapter1.fill (DATASET11);
Build and run the project and the result. I am the data in the DataGrid control.



About the Author:Mahesh is admin and founder of C # Corner. Mahesh has over 5+ years of programming experience in VC + +, MFC, VB, SQL Server, atl/com, and COM +. Mahesh ' s background includes Master ' s in Computer and B.Sc. Other achievements are MCP in VC + + 6.0. He presently engaged with Kruse, Inc. Downingtown, PA, US as a software engineer. More details ...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.