Preventing changes in a DataSet

  • Thread starter Thread starter Manuel
  • Start date Start date
M

Manuel

My first problem was filtering the results returned from a Typed DataSet.
This is because I find it moronic to retrieve an entire table when you're
only going to use a few rows.
I "solved" this by modifying the code behind the DataSet. I changed the
CommantText line in the InitCommandCollection() of the DataTable. But now
whenever I modify the DataSet the IDE overwrites my changes!

I would love a solution either problem.
1) Filter the records to be retrieved by a Typed DataSet
or
2) Lock my changes to the DataSet so I can add/delete tables in my DataSet
and not loose the changes.
 
Solution 3:

Don't use any of the wizards in VS.NET. Write all the code yourself, and
these kinds of problems will all disappear.
 
Manuel - unless I'm misunderstading you, I don't understand the problem.

If you are talking about "retrieve an entire table" in the sense that you
are getting all the values from the DB, you can work around this by
narrowing your query.

Or, if you mean you don't want to retrieve the whole datatable b/c you only
need a few rows, you can use DataTable.Select to get just the rows you want,
or use a DataView and filter the data (by specifying the .Rowfilter), then
just iterate through the rows that are left. Either way you'll be working
with a subset of the data.
 
Thank you Ryan for your reply.
Please correct me on this. As far as I know, when you call the
DataAdapter.Fill(DataTable) method using Typed DataSets, all rows of the
table get loaded into memory. Is this right or are the rows retrieved when
you call the DataTable.Rows (calling all records) or DataTable.Select
(selecting a few)?
 
When you call Fill, all of the rows matching your query are loaded into
memory. From there you can use DataTable.Select or one of the other methods
to restrict those rows. If you don't need the data in the first place, then
the best bet is to just use a query (at the db level) that pulls less data
on an as you need it basis.
 
Back
Top