Reputation: 2035
DataSet exportData = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(getOutput);
da.Fill(exportData);
exportData.HasChanges()
ExportData.hasChanges()
always returns false. Why? It should return true since it has a lot of new records inserted.
Upvotes: 1
Views: 3131
Reputation: 48570
This value becomes true if you made changes to dataset and have not called "DataSet.AcceptChanges"
. In the meantime you can call RejectChanges
to roll back to last time AcceptChanges
were called.
Upvotes: 0
Reputation: 726909
You misunderstood the meaning of HasChanges
. When you ask for HasChanges
, you
Get a value indicating whether the DataSet has [your] changes, including new, deleted, or modified rows.
When you read from the DB, your data set is unchanged from the DB's perspective: it has exactly what's in the database, i.e. it is "clean". When you add, change, or remove data in the data set, the data set gets "dirty", so HasChanges
starts returning true
.
Upvotes: 1
Reputation: 7028
Try this using AcceptChangesDuringFill
DataSet exportData = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(getOutput);
da.AcceptChangesDuringFill = false;
da.Fill(exportData);
exportData.HasChanges();
Upvotes: 1
Reputation: 460238
Because the last what DataAdapter.Fill
will do is to call AcceptChanges
. You can change this behaviour with the AcceptChangesDuringFill
property(default true
).
In general the RowState
is used to determine what to do with this record. If you add a new record to a DataTable, it's RowState
will change to Added
. Now a DataAdapter would know what to do when he should update this table.
But because actually you haven't added new records it would double all records if the default wouldn't be AcceptChangesDuringFill
.
Upvotes: 2