How to create DataSet without Databse

A Dataset serves as a comprehensive container that holds a collection of data retrieved from a Data Source. Within the Dataset, there are two important components: the DataTableCollection and the DataRelationCollection. The DataTableCollection contains zero or more DataTable objects, each representing a table of data. These DataTables can be populated with rows and columns, forming the structure of the data set.


The Dataset can encompass data for one or more members, where each member corresponds to a row in the Dataset. This means that the Dataset can accommodate multiple records or entities, depending on the number of rows present. It offers a flexible and versatile approach to store and manage data, regardless of the specific Data Source.

Manually populate a Dataset

In addition to retrieving data through SQL statements, we also have the ability to manually populate a Dataset with data. This process involves creating a DataTable object and defining its structure by specifying columns and data types. We can then add rows of data to the DataTable programmatically. By repeating this process for multiple DataTables, we can populate the Dataset with the desired data without directly interacting with the Data Source.

This capability allows for greater flexibility in scenarios where we need to manipulate or analyze data outside the confines of traditional SQL queries. It enables us to manually curate and shape the data within the Dataset, tailoring it to specific requirements or transformations.

Full Source VB.NET
Imports System.Data.OleDb Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim ds As New DataSet Dim dt As DataTable Dim dr As DataRow Dim idCoulumn As DataColumn Dim nameCoulumn As DataColumn Dim i As Integer dt = New DataTable() idCoulumn = New DataColumn("ID", Type.GetType("System.Int32")) nameCoulumn = New DataColumn("Name", Type.GetType("System.String")) dt.Columns.Add(idCoulumn) dt.Columns.Add(nameCoulumn) dr = dt.NewRow() dr("ID") = 1 dr("Name") = "Name1" dt.Rows.Add(dr) dr = dt.NewRow() dr("ID") = 2 dr("Name") = "Name2" dt.Rows.Add(dr) ds.Tables.Add(dt) For i = 0 To ds.Tables(0).Rows.Count - 1 MsgBox(ds.Tables(0).Rows(i).Item(0) & " -- " & ds.Tables(0).Rows(i).Item(1)) Next i End Sub End Class


While SQL statements are commonly used to populate the Dataset, we also have the flexibility to manually create DataTables and add data to them, offering greater control and customization.