// Fetch data into a disconnected DataTable
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Customers", connection);
DataTable dataTable = new DataTable();
adapter.Fill(dataTable);
// Perform operations on the DataTable
// ...
// Update changes to the database
adapter.Update(dataTable);
}
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Products", connection);
DataTable dataTable = new DataTable();
adapter.Fill(dataTable);
// Data is now available in the 'dataTable' for offline processing
}
// Create a new DataRow and add it to a DataTable
DataRow newRow = dataTable.NewRow();
newRow["ProductName"] = "New Product";
newRow["Price"] = 50.0;
dataTable.Rows.Add(newRow);
// Later, update the database to insert the new data
adapter.Update(dataTable);
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Orders", connection);
DataTable dataTable = new DataTable();
adapter.Fill(dataTable);
// Filter data to fetch specific records
DataRow[] specificRows = dataTable.Select("OrderDate > '2023-01-01'");
// 'specificRows' now contains records that meet the condition
}