Working With oledb Adapter

來源:互聯網
上載者:User
 
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 in no time. You just set some properties of these controls and use wizards to generate your code. In couple of minutes, you develop a full-fledged working application.
In this series of articles, my first article is OleDb Data Adapter Controls in VS.NET. In this article, I'll show you how to display data in a DataGrid control by writing only one line of code. You just follow these simple steps:
Step 1: Create Project
Pick Visual C#->Windows Application project and type your project name and pick a directory.

Step 2: Add OleDb 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.
First screen is about the wizard.

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

Next page provides you options to use SQL Statements or stored procedures.

Next step is to generate SQL statement. You use Query Builder button to build a query.

This option let you pick your database tables.

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

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

Last page shows you the activities wizard finished.

Step 3: Generate DataSet
Next step is to generate DataSet and connect DataSet to a DataView component. You generate a DataSet by using "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 you want from the list.

By clicking "OK" button, wizard generates a dataset and shows you it's properties dialog. You can change DataSet name and other properties. "View Schema" option shows you the XML Schema for this dataset added by the wizard and "DataSet Properties" option shows you 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 this dataset with a DataView. Drag a DataView control from Toolbox->Data and set it's table property to your DataSet's table.

Step 5: Attach DataView with the DataGrid Control and Fill the DataSet
Now drag a DataGrid control from Toolbox->WinFroms to the form and set its DataSource property to DataView.

Now fill the data from DataAdapter to the DataSet by calling DataAdapter's Fill method. I write this code after InitializeComponent();
InitializeComponent();
oleDbDataAdapter1.Fill(dataset11);
Build and run the project and see the result. I see my 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 Science and B.Sc. maths. Other achievements are MCP in VC++ 6.0. He presently engaged with Kruse, Inc. Downingtown, PA, US as a software engineer. More details...

相關文章

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。