Difference between DataSet.Clear and DataSet.Reset?

B

Bill Todd

I have a DataSet with a DataTable and DataColumns that were created at
design time. If I call DataAdapter.Fill then DataSet.Clear then
DataAdapter.Fill again I get a constraint violation exception on the
second call to Fill.

However, if I call Fill then WriteXml then Clear then ReadXml I do not
get an exception.

If I call DataAdapter.Fill then DataSet.Reset then DataAdapter.Fill no
exception is thrown.

My question is, what is the difference between DataSet.Clear and
DataSet.Reset and why do I get an exception when I call Fill, Clear,
Fill?

Thanks,
 
G

Guest

Hi Bill,

We have reviewed this issue and are currently researching on it. We will
update you ASAP.
Thanks for your patience!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
M

Miha Markic [MVP C#]

Hi Bill,

The clear just invokes Clear on all tables.
While the Reset does more (on top of Clear)- it removes relations, foreign
key constraints, and all tables.

HTH
 
K

Kevin Yu [MSFT]

Thanks for Miha's quick response.

Hi Bill,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to know the difference between
DataSet.Clear and DataSet.Reset. If there is any misunderstanding, please
feel free to let me know.

Just as Miha said, DataSet.Clear just clear the data in all the tables,
while DataSet.Reset removes the schemas. Also, ReadXml method first reset
the DataSet, so there will not be exceptions thrown.

HTH. If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
B

Bill Todd

Does DataSet.Reset remove all schema information or just the schema
information added at runtime? For example, suppose I add DataTable,
DataColumn, DataRelation and Constraint objects to a DataSet at design
time. At runtime I call

ADataAdapter.Fill(MyDataTable);

to load data into the DataTable. If I call DataSet.Reset what is left
in the DataSet? According to the on-line help the DataSet should be
restored to the state it was in just before I called Fill. All of the
design time schema objects should still exist. Is that correct?
 
K

Kevin Yu [MSFT]

Hi Bill,

As far as I know, if you are working on a typed DataSet with schema, when
calling Reset method, all the schema information will be removed whether
they are added duing design time or runtime.

According to MSDN documentation, If we need to reset the DataSet to the
state as we expect, we have to should override Reset to restore a DataSet
to its original state in its subclasses. HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
K

Kevin Yu [MSFT]

Hi Bill,

I'd like to know if this issue has been resolved yet. Is there anything
that I can help. I'm still monitoring on it. If you have any questions,
please feel free to post them in the community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top