TechyMedia

A .NET Technology blog | .NET,C# Progamming,C# tutorials,WPF WCF|Software Engineer

NAVIGATION - SEARCH

What is Typed Dataset In C#,VB.NET?

Typed Datasets(Strongly Typed Datasets) are specialized Dataset class.Typed datasets are strongly typed and hence gives compile time error when assigned data column with wrong type value.You can create Typed Dataset in 2 different manners.Using Visual Studion typed dataset designer ad using XSD.exe.

Typed Datasets(Strongly Typed Datasets) are specialized dataset class.Typed datasets are strongly typed and hence gives compile time error when assigned data column with wrong type value.

How to Generate Typed DataSet?

You can create Typed Dataset in 2 different manners.Using Visual Studion typed dataset designer ad using XSD.exe.

 

Creating Typed Dataset Using XSD.exe

1) First need to create the xsd file from database.For that do the below given code
   

        SqlConnection sqlConn = New SqlConnection("Data Source=YourDBserverName;userid=YourUID;
password=Yourpassword;Initial catalog=Employee;"); SqlDataAdapter dataAdapter = New SqlDataAdapter("Select * from Emp", sqlConn); DataSet dataSet = New DataSet(); dataAdapter.FillSchema(dataSet, SchemaType.Mapped, "Emp") dataSet.WriteXmlSchema("D:\Emp.xsd")

  
2) Launch Visual Studio command prompt and execute the command  xsd.exe Emp.xsd /d /outputdir:D:\Test

 

Creating a Typed DataSet using Visual Studio.NET

Using visual studio development environment it is quite easy to create a Strongly Typed Dataset. See the below explained simple steps

Step by Step procedure o create a typed dataset by using visual studio

1. Launch Visual Studio
2. Go To File menu and choose to Create New Project(winform Project or Console Application).Give a Project Name and Click OK.
3. Right click on Project in solution explorer and Choode Add New Item
4. Select DataSet from the templates shown and give the name of the Dataset and click Open.
5. Go to Server explorer and connect to the database
6. Select the Table for which you need to create a typed datasetand drag and drop that table in to the dataset designer window.
7.Your typed dataset is ready and you can use this typed dataset in your code to access the corresponding datatable and columns.

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading