Reader Level:
ARTICLE

ADO.NET Database Explorer

Posted by Pramod Singh Articles | ADO.NET January 20, 2001
The sample connects to the SQL server database and shows you a tree view like interface of all the tables.
  • 0
  • 0
  • 29745
Download Files:
 

The attached program is a C# program which demonstrates how to use ADO.NET objects including ADOCOnnection, ADOCommand, ADODataReader, ADOParameters. Microsoft Data Access Technolgoy got changed with the ADO.NET. This sample application can help developer who have worked with ADO(version1.X or 2.X) in understanding the ADO.NET.

The ADOConnection object of ADO.NET is very similar to ADODB.Connection Interface of the ADO, here to we have to provide the same property value like Provider, Database  or simply ConnectString. The ADOCommand is same as ADODB.Command same is the case with ADOParameter, the difference is the Exceute method.

ADODB.Command.Excecute was a function which used to return a Recordset, in ADO.NET it is overloaded method which can take a parameter of type ADODataReader or of Interface IDataReader.

public virtual void Execute(ADODataReader);

public override void Exceute(IDataReader);

The difference between these two overloaded methods are ADODataReader is a sealed (Class can't be inherited) class which itself Implements the Interface IDataReader. IDataReader is a Interface and any one can implement it and use it in its own way. The ADODataReader is a FORWARD only stream of data records.One notable difference is ADODataReader is created from Execute method of ADOCommand and not from the constructor.NOTE : While the ADODataReader is in use, the associated ADOConnection is busy serving the ADODataReader. While in this state, no other operatons can be performed on the ADOConnection other than closing it. This will be the case until the Close method of the ADODataReader is called. As with ADO we use ForwardOnly cursor, ADODataReader can be considered as ForwardOnly.The functionality of  ADOCommand and ADODB.Command are allmost same with same type of Interfaces ,in ADODB for parameter you were to use ADODB.Parameter(s) and in ADO.NET you use ADOParameter(s) , allmost all the properties and method with ADOCommand and ADODB.Command are same . THe difference is ADODataReader , persons with ADODB must we thinking where is the most used ADODB.Recordset .... , there is no RecordSet at least no RecordSet terminology in ADO.NET , allmost all the architecture of ADO.NET is different from ADODB,ADOX or ADOR. let see the senario in which you fired a ADOCOmmand to access a Stored Procedure form the Database and this Stored Procedure is trurning multiply rows ? In ADODB Recordset you have a NextRecordset here to in ADODataReader you have the same functionality but with a twist. ADODataReader HasMoreResults which is a property which return boolean , if true this indicates that there are more than one Data stream is present ,once you know that there is more Data Stream then you can use a function of ADODataReader called nextResult which will move the current data strem to the next one and you can go on in a loop to get all the Data Streams from the ADODataReader
This and more are there in the sample application. The attached sample application asks the use to enter the SQL Server information and the database on you want to work , it make the connection and get back you all the tables stored procedure and view present in the database in a treeview.With .NET Microsoft have made all the controls or object as programmable, some time this makes your job easier and some time hard too like the treeview (If u are a VB programmer then it was very easy to just add nodes and all ) but here in VB.NET or in C# you have to do a lot many thing to get it done , but once you understand how then you will feel how easy it is to do.

The sample application just have a treeview which display the Node as Tables,View and Strode Procs. but u can extend this and can get more information of GUI by adding a listview and displaying the relevent information in that.If you want to do that then there is a suggestion. Use DataSet and DataTable to do that. You have to just get the value in DataTable's instead of ADODataReader and add these values in DataSet, so these will act as a disconnected database or in memory database from where when ever a user clicks on the TreeView node, like a user clicks on the Table Employee , in the adjecent list view display all the information about that table which you have in the DataTable in the ListView . This way this application will look like SQL Server Enterprise manager with very miminum or Read Only Enterprise Manager.

As the application that is attached with this article doesn't uses DataSet and DataTable I have not described them . but I would try to develop some meaning full application that can uses most of the ADO.NET class and will try to explain the ADO.NET from the ADODB perpective , because most of the developer how will see this ADO.NET are bound face problems.

Please drop me a line or two with the type of application you would like to see and on which topic of ADO.NET you wanted to know more, I will try my best to do that and explain that with ADODB perspective.

Good luck and enjoy C#.

COMMENT USING

Trending up