using System.Data; DataSet dataSet = new DataSet(); dataSet.ReadXml("data.xml"); // Do some changes to the dataset if(dataSet.HasChanges()) { // Save changes to the database }
using System.Data.SqlClient; SqlConnection connection = new SqlConnection(connectionString); SqlCommand command = new SqlCommand("SELECT * FROM Customers", connection); SqlDataAdapter adapter = new SqlDataAdapter(command); DataSet dataSet = new DataSet(); adapter.Fill(dataSet); // Do some changes to the dataset if(dataSet.HasChanges()) { SqlCommandBuilder builder = new SqlCommandBuilder(adapter); adapter.Update(dataSet); }In this example, we are loading a dataset from a SQL Server database using a data adapter and making some changes to it. We are then checking whether there are any changes made to the dataset using the HasChanges property. If there are changes, we can create a command builder to generate update, delete, and insert commands for the data adapter and call the adapter's Update method to save the changes to the database. Package library: System.Data.SqlClient
public HasChanges ( ) : bool | ||
return | bool |