|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
DataSet.Clear required before loading new data?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 "Rick Lederman" <r***@soaringsoftware.com> wrote in message If you have a Key on the Table and you use the same query, then you can news:OQUY419DGHA.336@TK2MSFTNGP14.phx.gbl... > 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? 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/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatacommondbdataadapterclassfilltopic.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. Show quote > > Thanks > > Rick Lederman > 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 Show quote "W.G. Ryan - MVP" <WilliamRyan@nospam.gmail.com> wrote in message news:uFOEKA%23DGHA.1120@TK2MSFTNGP11.phx.gbl... > > "Rick Lederman" <r***@soaringsoftware.com> wrote in message > news:OQUY419DGHA.336@TK2MSFTNGP14.phx.gbl... >> 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/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatacommondbdataadapterclassfilltopic.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 >> > > Rick,
I would use in your situation if this is needed probably the rowcollection.clear. http://msdn2.microsoft.com/en-us/library/system.data.datarowcollection.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 |
|||||||||||||||||||||||