C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » .NET Framework »

Typed DataSet


Posted Date: 07 Oct 2004    Resource Type: Articles    Category: .NET Framework
Author: Kamliesh NadarMember Level: Gold    
Rating: 1 out of 5Points: 7



A typed DataSet is a class that derives from a DataSet. As such, it inherits all the methods, events, and properties of a DataSet. Typed DataSet uses information in the Schema file. Additionally, a typed DataSet provides strongly typed methods, events, and properties. This means you can access tables and columns by name, instead of using collection-based methods.


Now here I will present a example to create a Typed Dataset and pass this from UI layer to DataAccess layer and back to populate values on a Datagrid.

To create a Typed Data Set, left click on the solution explorer and select add -> Add New Item. Now from the dialogue box select Dataset, and name it CustTypedDs.xsd. Now open the Server explorer and drag and drop the “Customers” Table, from the Northwind database.

In the UI layer (Customer.aspx), place a button & DataGrid. On button click event, create an object, which is reference to Data Access Layer and call the function “FnCustomers”. This function returns a typed dataset which data is displayed on the datagrid.

“FnCustomers” is a function in the Data Access Layer which is going to take data from database and fill the Typed dataset and will pass it to UI Layer.

CODE -

Customer.aspx.cs

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using TDS;

namespace TDS
{

public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.DataGrid DataGrid1;

DAccessLayer ObjDAccessLayer=new DAccessLayer();
CustTypedDs ObjSchema=new CustTypedDs();

private void Page_Load(object sender, System.EventArgs e)
{
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion


private void Button1_Click(object sender, System.EventArgs e)
{
ObjDAccessLayer.FnCustomers(ObjSchema);
DataGrid1.DataSource=ObjDAccessLayer.FnCustomers(ObjSchema);;
DataGrid1.DataBind();
}
}
}


DataccessLayer.cs

using System;
using System.Data;
using System.Data.SqlClient;
using TDS;

namespace TDS
{

public class DAccessLayer
{
public CustTypedDs FnCustomers(CustTypedDs dsObj)
{
//Get the connection from Web.Config file
String ObjVarConnection= System.Configuration.ConfigurationSettings.AppSettings["Connection"] ;
SqlConnection ObjConnection= new SqlConnection(ObjVarConnection);
SqlDataAdapter da = new SqlDataAdapter("select * from Customers",ObjConnection);
da.Fill(dsObj,"Customers");
}
}
}


Hope after going through this article you would got to know the benifit of using a Typed Dataset and how easy it is to use it.




Responses

Author: Sudheer Reddy    30 Apr 2005Member Level: Silver   Points : 0
Thank you for your article... I have few Q's on this article.. can you clarify please.
1. What are differences b/w Typed & UnTyped Datasets.
2. Performence wise which is better one?

Sudheer.


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Delegate with a simple example
Previous Resource: For passing parameter from TextBox to Crystal report Using vb.Net
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use