Learn ASP.NET Core 2 and Angular 6 in October 2018. Instructor-led online courses by Bipin Joshi. Read more...
Instructor-led Online Courses by Bipin Joshi : ASP.NET Core | Angular | Design Patterns
Registration open for October 2018 batches. Read more here.

<%@ Page %>

Creating DataSet Programmatically

Introduction

ADO.NET provides a powerful way to create objects like dataset and datatale dynamically through code. This code sample illustrates these capabilities of ADO.NET.

Namespace involved

We will need following namespace to work with the examples :

  • System.Data

Steps involved

Following steps are involved in creating a dataset programmatically :

  • Create a DataSet object
  • Create a DataTable object
  • Create DataColumn objects with required data types
  • Add DataColumn objects to DataTable object
  • Add DataTable object to DataSet
  • Use the DataSet in your code

Sample Code

Dim ds As DataSet
Dim tbl As DataTable
Dim col1,col2 as DataColumn

ds = New DataSet()
tbl = New DataTable("mytable")
col1 = New DataColumn("mycolname1", Type.GetType("System.Int32"))
col2 = New DataColumn("mycolname2", Type.GetType("System.String"))

tbl.Columns.Add(col1)
tbl.Columns.Add(col2)

ds.Tables.Add(tbl)


Bipin Joshi is a software consultant, trainer, author and spiritual yoga mentor having 23+ years of experience in software development. He teaches private online courses in ASP.NET Core and Angular to individuals and small groups. He is a published author and has authored or co-authored books for Apress and Wrox press. Having embraced the Yoga way of life he also teaches Ajapa Yoga to interested individuals. To know more about him click here.

He will be teaching ASP.NET Core 2.1 and Angular 6.1 in October 2018. Click here for his online course schedule and more details.

Get connected : Twitter  Facebook  Google+  LinkedIn

Posted On : 18 July 2001


Tags : ADO.NET Data Access SQL Server