Click here to Skip to main content
Licence 
First Posted 21 Aug 2006
Views 42,779
Bookmarked 14 times

Accessing Data Using Object Data Source in ASP.net 2.0 and C#

By | 21 Aug 2006 | Article
To access data base and read and bind data using objcect data source

Introduction

Accessing Data Using Object Data Source (ASP.net 2.0) in C#

 

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

 

DataBinging 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.

 

Sample image 

 

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 .

 

Sample image

 

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.

 

Sample image

 

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.

 

 

 

 

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Praveen Kumar T

Web Developer

India India

Member


I am Working as a Software Engineer. My interests are in asp.net 2.0 and C#.I am an MCA and currently concentrating on Microsoft Technologies.
praveen.theendakkara@marlabs.com
 


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralNeed to change the contents !! Pinmembersolai rajan2:18 9 Aug '09  
GeneralMy vote of 1 PinmemberMember 39942596:01 29 Jun '09  
GeneralMy vote of 1 PinmemberMember 16176969:31 25 Nov '08  
GeneralGetting error with this procedure PinsussNewbie923932919333117:48 12 Dec '07  
Generalworking sh*t PinmemberMember #380862221:01 8 Feb '07  
Generalvery bad article Pinmemberdeepaktripathi21:33 31 Jan '07  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 22 Aug 2006
Article Copyright 2006 by Praveen Kumar T
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid