7. May 2013 04:59
.NET . C#
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;
SqlDataAdapter dataAdapter = New SqlDataAdapter("Select * from Emp", sqlConn);
DataSet dataSet = New DataSet();
dataAdapter.FillSchema(dataSet, SchemaType.Mapped, "Emp")
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.