Different Way of Using ObjectDataSource

The ObjectDataSource control enabled you to bind Data Bound controls such as Grid View,Details View and Form View controls to a component. You can use the ObjectDataSource control to easily build multi-tier applications with the ASP.NET Framework. The ObjectDataSource control enables you to cleanly separate your User Interface Layer from your Business Logic and Data Access Layers.

An ObjectDataSource control can represent any type of object in the .NET Framework. ObjectDataSource control use with collections,ADO.NET Data Reader, Dataset, LINQ to SQL queries and web services.

The ObjectDataSource control includes two properties named TypeName and SelectMethod in all below example. TypeName property contains the name of the component that you want to represent with the objectDataSource control. SelectMethod property represents the method of the component that you want to call when selecting data.

Download Complete Source code here

Using Collections :-

                This is an simple collection example. Where its display an Customer Name using List collections.

HtmlCode

ObjDSCollection class looks like below one

Code

 

Using DataReader :-

The ADO.NET DataReader object provides you with a fast,read-only representation of database data. If you need to retrieve database

records in the fastest possible way, then you should use a DataReader object.

 HtmlCode

 

ObjDataReader class looks like below one :-

SourceCode

I had use three ADO.NET objects :- Connection,Command, and DataReader objects.Command object uses the connection object to connect to database. Then records are returned from command object and used by DataReader object. WebConfigurationManager is used to retrieve the database connection string from web configuration file.

Using DataSet :-

    You also ca use the ObjectDataSource when you need to represent to ADO.NET DataSet. Using a DataSet is slower than using a DataReader.

        However, you can perform advanced operations, such as filtering and sorting, on data represented with a DataSet.

HtmlCode

ObjDataSet class looks like below one :-

SourceCode

  Using LINQ  :-

          LINQ to SQL is the preferred method of data access in the .NET Framewor 3.5. You have to first create an CustomerLINQDataContext. The

        easitest way to create the DataContext is to select LINQ to SQl Classes template. Go to menu-->Website-->Add New Item and select LINQ to SQL Classes template. Name the LINQ to SQl Classes CustomerLINQ.       

 HTMLCode

ObjLINQ class looks like below one :-

Source

Customer.dbml looks like below one.

CreateingDBML

    Using Web Service :-

        Web services enable you to share information across the Internet. When you communicate with a remote web service, you use a local proxy class

        to represent the web service located on the remote machine. You can use the ObjectDataSource to represent this proxy class.

 

    HTMLCode

ObjWebService web service look like below :-

SourceCode

Output of all the above except Collection Demo is as below :-

 

 

I hope this will help you in using ObjectDataSource in different way.


1 Comment

Comments have been disabled for this content.