Here first we see about how to create dataset?
Syntax:
DataSet datasetname = new DataSet();
Example :
DataSet ds = new DataSet();
Now we created the dataset with name of ds. Hereby we can add multiple data tables to the dataset.
How to add table?
Syntax:
datasetname.Tables.Add(datatable);
Example:
ds.Tables.Add(dt);
Now we added datatable dt in dataset ds. likewise we can add multiple datatables in dataset.
How to Delete Datatable from dataset?
Syntax:
Datasetname.Tables.Remove(datasetname.Tables[position]);
Example:
ds.Tables.Remove(ds.Tables[ds.Tables.Count-1]);
Here we deleted last Datatable from dataset ds.
Here by making relationship between two tables also possible with the use of foreign and primary key.
Example to set primary key for a Datatable:
dt.PrimaryKey = new DataColumn[] { dt.Columns["id"]};

Join the conversation! Your thoughts help the community grow.