Working With oledb Adapter

 
Submitted ByUser LevelDate 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...

时间: 2024-07-30 11:45:38

Working With oledb Adapter的相关文章

一个支持SqlClient和OleDb的ADO.NET常用操作通用类

using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.SqlClient; using System.Configuration; using System.Data.OleDb; /* *************************************** * * *作者:GhostBear * *博客:http://blog.csd

access+visualc#-adapter 从未被使用过

问题描述 adapter 从未被使用过 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.OleDb; namespace 专科医院门诊系统_眼科

处理The content of the adapter has changed but ListView did not receive a notification异常

istView在更新时报异常: ERROR/AndroidRuntime(15260): java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only

关于Android聊天界面中用使用adapter导致内存泄露的问题,目前不知道如何改善,大神帮忙看看

问题描述 关于Android聊天界面中用使用adapter导致内存泄露的问题,目前不知道如何改善,大神帮忙看看 之前一段时间使用一段时间老是导致内存升高,而且内存也不回收,一步一步的排除了很多地方, 到最后发现问题是出在adapter中,但是也不知道怎么改了. 大神帮看看哪些地方会导致内存泄露! public void setmList(List mList) { if (isgroup) { isDiaplayNickName = SharePreferenceUtil.get_Boolean

adapter和facade模式在Ajax中的应用

ajax 一.     起因 在看<Ajax in action>的时候,看到它在介绍Adapter和Facade两种模式.由于目前Web开发的特色,特别是客户端Js脚本的开发,需要面对很多的变化和跨平台的挑战,所以,如果应用Adapter和Facade模式,将会非常有益于提高我们软件的可维护性,以及降低总体开发成本.   二.     什么是Adapter和Facade模式 1.          Adapter模式 1.1.定义: The Adapter Pattern converts

C#中的Adapter设计模式浅析

把一个类的接口变换成客户端所期待的另一种接口,从而使原本接口不匹配而无法在一起工作的两个类能够在一起工作. 意图 把一个类的接口变换成客户端所期待的另一种接口,从而使原本接口不匹配而无法在一起工作的两个类能够在一起工作. 场景 假设网络游戏的客户端程序分两部分.一部分是和服务端通讯的大厅部分,大厅部分提供的功能有道具购买.读取房间列表.创建房间以及启动游戏程 序.另一部分就是游戏程序了,游戏程序和大厅程序虽然属于一个客户端,但是由不同的公司在进行开发.游戏大厅通过实现约定的接口和游戏程序进行通讯

MS SQLServer OLEDB分布式事务无法启动的一般解决方案

server|sqlserver|分布式|解决 本文属spanzhang原创,其blog地址为:http://blog.csdn.net/spanzhang.引用或转贴请注明出处,谢谢!! 服务器: 消息 7391,级别 16,状态 1,行 6该操作未能执行,因为 OLE DB 提供程序 'SQLOLEDB' 无法启动分布式事务.[OLE/DB provider returned message: 不能在指定的事务处理器中获得新事务.]------------------------------

初学者来认识OLEDB和ODBC的区别

ODBC(开放数据库互连):是Microsoft引进的一种早期数据库接口技术.它实际上是ADO的前身.早期的数据库连接是非常困难的.每个数据库的格式都不一样,开发者得对他们所开发的每种数据库的底层API有深刻的了解. 因此,能处理各种各样数据库的通用的API就应运而生了.也就是现在的ODBC(Open Database Connectivity), ODBC是人们在创建通用API的早期产物.有许多种数据库遵从了这种标准,被称为ODBC兼容的数据库. OLEDB(对象链接和嵌入数据库)位于ODBC

使用速度更快的OLEDB取代ODBC连结

仍旧在使用ODBC系统或文件DSN连接数据库吗?请用速度更快的OLEDB提供者技术取代DSN连接数据库,不必再恳求你的ISP(或你的数据库管理员/Web管理员)为你创建系统DSN,也不必因为移动文件而修改配置. OLEDB处于ODBC层和应用之间.对于ASP页面来说,ADO是OLEDB上面的一种"应用".ADO调用首先发送给OLEDB,然后才被发送给ODBC层.但是你也可以直接连接到OLEDB层,而且如果你这么做了,你就会看到性能的进一步提升.那么,如何才能直接连接到OLEDB呢? 如