Mid ADO.NET

Optionally, you can load the result into a DataSet to work with multiple tables or store?

the data in a DataReader.

Example:

string query = "SELECT Customers.CustomerID, Customers.CustomerName,

Orders.OrderID, Orders.OrderDate " +

"FROM Customers " +

"INNER JOIN Orders ON Customers.CustomerID =

Orders.CustomerID";

SqlCommand command = new SqlCommand(query, connection);

connection.Open();

SqlDataReader reader = command.ExecuteReader();

while (reader.Read())

Follow:

Console.WriteLine("Customer: " + reader["CustomerName"] + ",

Order ID: " + reader["OrderID"]);

reader.Close();

connection.Close();

Alternatively, you can use a DataSet to load data from multiple tables, which will maintain

the relationships between the tables.

Example (Using DataSet):

string query = "SELECT * FROM Customers; SELECT * FROM Orders";

SqlDataAdapter adapter = new SqlDataAdapter(query, connection);

DataSet dataSet = new DataSet();

adapter.Fill(dataSet);

Here, dataSet.Tables[0] will contain Customers, and dataSet.Tables[1] will

contain Orders.

More from ADO.NET Core Tutorial

All questions for this course