SIGN UP MEMBER LOGIN:    
ARTICLE

Accessing Data using Object Data Source in ASP.Net 2.0 and C#

Posted by Praveen Kumar T Articles | ADO.NET in C# August 23, 2006
This tutorial demonstrates how to bind data against Objects using Visual Studio 2005.
Reader Level:

One of the best methods to read or write data is Data binding against objects.

The below tutorial demonstrates how to build ASP.NET 2.0 that binds data against Objects using Visual Studio 2005 .

1. Create App_Code Folder in your Project root.

2. Right-click on the App_Code and select Add->Add New Item to add a new DataSet called "Sample.xsd" to the project.

 

 

 

3. Double click on DataSet Sample.xsd. You will get a tool box for your Data set.


4. Grab a Table Adapter control.

 

You may see another Table Adapter as shown below.

 

5. Create appropriate connection string or select already created one.

6. Click Next and tick "Use Sql Statements" and write a Query to select the rows. You can use the Query Builder for automatic queries and check the results there it self.

 

7. Rename DataTable1 to Sample (for an example). Which renames the adapter also.

 

8. After successful creation of the sql query which creates a Method by default say GetData().

 

Right-click on the App_Code and select Add->Add New Item to add a new Class file called "AssignValues.cs" to the project.

 

 

Double Click on the class and create a method in it

 

public class AssignValues

{

 

   public void Fill(GridView gdv)

    {

 

      gdv.ID = string.Empty;

      SampleTableAdapters.MemberTableAdapter mtadptr = null;              

      mtadptr = new SampleTableAdapters.MemberTableAdapter();

      Sample.MemberDataTable dt=null;

      dt=mtadptr.GetData();

      gdv.DataSourceID=string.Empty;

      gdv.DataSource=dt;

      

      gdv.DataBind();

    }

}

 

Explanation for the above code:

 

Grid view is an object parameter you passing it from in which event you need to fill the data.Then creating an object of  Sample data set dt and filling the data  into it and bind it.

 

After that you can make an instance of the class and call the method in any other c# code page of the Project files. Pass the parameter Grid View say GridView1 after grabbing a Grid view from the Tool Box. 

Login to add your contents and source code to this article
share this article :
post comment
 

This is the most useless article ever written - it should be deleted

Posted by dgg23 Jun 28, 2007
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Team Foundation Server Hosting
Become a Sponsor