PC Review


Reply
Thread Tools Rate Thread

DataSet.Clear required before loading new data?

 
 
Rick Lederman
Guest
Posts: n/a
 
      2nd Jan 2006
Is a DataSet.Clear required before new data is brought into the dataset?

I.E. daMyDataset.Fill(dsMyDataset)

Can I simply refill the dataset with new data intended to totally replace
the old data, or must I do a .Clear first?

Thanks

Rick Lederman


 
Reply With Quote
 
 
 
 
W.G. Ryan - MVP
Guest
Posts: n/a
 
      2nd Jan 2006

"Rick Lederman" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Is a DataSet.Clear required before new data is brought into the dataset?

--It depends.
>
> I.E. daMyDataset.Fill(dsMyDataset)
>
> Can I simply refill the dataset with new data intended to totally replace
> the old data, or must I do a .Clear first?


If you have a Key on the Table and you use the same query, then you can
refresh it. However if youdon't have a key on the table, then it will add
duplicates of the rows.

http://msdn.microsoft.com/library/de...sfilltopic.asp

Here's a summary of the rules to have it refresh vs fill over again:

When using subsequent Fill calls to refresh the contents of the DataSet, two
conditions must be met:

1.. The SQL statement should match the one initially used to populate the
DataSet.
2.. The Key column information must be present.
If primary key information is present, any duplicate rows are reconciled and
only appears once in the DataTable that corresponds to the DataSet. Primary
key information may be set either through FillSchema, by specifying the
PrimaryKey property of the DataTable, or by setting the MissingSchemaAction
property to AddWithKey.
>
> Thanks
>
> Rick Lederman
>



 
Reply With Quote
 
Rick Lederman
Guest
Posts: n/a
 
      2nd Jan 2006
Thanks! I am actually using the same dataset over & over for multiple uses.
With an ADO recordset, once the recordset was closed then I could use it for
something totally different (different query with different schema) with no
problem. Fortuneately the coding that I have been doing the last few days I
included a .Clear immediately after I was finished with the dataset. I was
remembering the DAO days when there was NO warning within any sample at all
about requiring a separate workspace and database for every recordset or
they could trash each other. So I started wondering how much of the same
trouble I might have with datasets as every example that I have seen simply
pulls in a set of data for a silly reason then does nothing else. This
latest version of .Net (2005) the VB samples are far better, but still don't
address multiple data accesses very well. I guess that is what experience
is all about, but the samples could help there.

Thanks again,

Rick



"W.G. Ryan - MVP" <(E-Mail Removed)> wrote in message
news:uFOEKA%(E-Mail Removed)...
>
> "Rick Lederman" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Is a DataSet.Clear required before new data is brought into the dataset?

> --It depends.
>>
>> I.E. daMyDataset.Fill(dsMyDataset)
>>
>> Can I simply refill the dataset with new data intended to totally replace
>> the old data, or must I do a .Clear first?

>
> If you have a Key on the Table and you use the same query, then you can
> refresh it. However if youdon't have a key on the table, then it will add
> duplicates of the rows.
>
> http://msdn.microsoft.com/library/de...sfilltopic.asp
>
> Here's a summary of the rules to have it refresh vs fill over again:
>
> When using subsequent Fill calls to refresh the contents of the DataSet,
> two conditions must be met:
>
> 1.. The SQL statement should match the one initially used to populate the
> DataSet.
> 2.. The Key column information must be present.
> If primary key information is present, any duplicate rows are reconciled
> and only appears once in the DataTable that corresponds to the DataSet.
> Primary key information may be set either through FillSchema, by
> specifying the PrimaryKey property of the DataTable, or by setting the
> MissingSchemaAction property to AddWithKey.
>>
>> Thanks
>>
>> Rick Lederman
>>

>
>



 
Reply With Quote
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      3rd Jan 2006
Rick,

I would use in your situation if this is needed probably the
rowcollection.clear.

http://msdn2.microsoft.com/en-us/lib...ion.clear.aspx

There is an error in the datatable.clear description on MSDN (reported by
me).
It describes at least partially the dataset.clear so I am now not sure what
is true and what not.
(All rows in *all* tables are removed)

I have the idea that the datatable.clear clears more than only the rows.

I hope this helps,

Cor



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to clear old data from a DataGridView and a DataSet? David Mayerovitch Microsoft VB .NET 0 30th Dec 2006 06:36 AM
Help! When I clear and fill a dataset, it loads new data in tables(1) scottin Microsoft VB .NET 1 19th Jan 2005 06:37 PM
Loading Data Into DataSet From XML =?Utf-8?B?QXJ0IENhYm90?= Microsoft Dot NET Compact Framework 5 2nd Jul 2004 11:53 PM
Loading Data into DataSet From XML =?Utf-8?B?QXJ0IENhYm90?= Microsoft Dot NET Compact Framework 6 30th Jun 2004 12:11 PM
Loading Primary key data into a dataset JerryK Microsoft ADO .NET 0 16th Oct 2003 01:20 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:56 AM.