ADO.NET mainly work with the data that we get from the data source.
While retrieving data we can get it using the connected approach or using the disconnected approach .
For retrieval we don't need to open and close the database and table connection.
Dataset is the collection of DataTables where multiple tables data can be stored.
So if we want multiple table to be returned we have to store it in the dataset.
class Program
{
static void Main()
{
// Create two DataTable instances.
DataTable table1 = new DataTable("patients");
table1.Columns.Add("name");
table1.Columns.Add("id");
table1.Rows.Add("sam", 1);
table1.Rows.Add("mark", 2);
DataTable table2 = new DataTable("medications");
table2.Columns.Add("id");
table2.Columns.Add("medication");
table2.Rows.Add(1, "atenolol");
table2.Rows.Add(2, "amoxicillin");
// Create a DataSet and put both tables in it.
DataSet set = new DataSet("office");
set.Tables.Add(table1);
set.Tables.Add(table2);
// Visualize DataSet.
Console.WriteLine(set.GetXml());
}
}
0 Comment(s)