DataSet and DataGridView


O

Oliver

Hi All,

As far as I know the two most common methods of using data in a database is
either by manually querying the database and manipulating the data to suit
the UI or using the designer to data bind automatically with minimum code. It
seems that the second method is faster during design time, but creates a hell
of a lot of code in the background.

Anyway, assume that in this question I used the designer method to databind
a DataGridView to the database and used the designer to modify the columns
and bindings without having to write a single peice of code.


The question I have here is twofold:

1. Every time a form or user control wants to databind to the designer
DataSet it creates a new instance of that dataset and all the
DataTableAdapters. That means a new instance of the DataSet with all it's
DataTable instances and Adapters and so forth. I.e. a lot of duplicated
memory that doesn't really need to be there.

Is there some way to make the DataSet a singleton using a static instance
that is shared to reduce the footprint? I was trying to create a class that
holds this static instance, but then I tried getting the designer to
recogines that static property and it doesn't see it. I could hack the
designer code, but wouldn't that get overwritten whenever the designer
refreshes?


2. I would like to be able to capture Insert and Update events in the form
of "TableNewRow" and "RowChanged" events in the designer created DataSet
class. I know of the "partial class" concept to extend existing classes,
however I'm not sure how to go about attaching to the RowChanged and
TableNewRow events in the DataSet.

Is there an Init method or OnLoad I can override in the DataSet or Adapters
to attach to these events? I tried clicking on a dataTableAdapter to see if
any properties/events appear but there is no "events" button. Once again, I
could hack the designer created class but I don't think that is safe. It's
not very "clean" either. I think the trick is somewhere in partial classes,
but I'm not sure how.


Any clues?

Thanks a million.
 
Ad

Advertisements

O

Oliver

Not technically relevant, but aslight correction:

When a form or control data binds to a designer DataSet it creates an
instance of the DataSet and the DataTableAdapters that you actually need.

I said it creates instances of ALL DataTableAdapters, but that's not true.
Only the ones you need for the binding to work.
 
C

Cor Ligthert[MVP]

Oliver,

You write a lot of text based on some wrong ideas, therefore try to think
about what I write below first.

OOP means that you are programming with reference and therefore there is
very few handling with real data.

Secondly instancing new objects is based on the fact that there is so much
memory and computers are so fast, that doing it in the ancient way is very
bad maintainable and gives more unwanted extra behaviour than benefits.

Cor
 
J

Jeff Gaines

Secondly instancing new objects is based on the fact that there is so much
memory and computers are so fast, that doing it in the ancient way is very
bad maintainable and gives more unwanted extra behaviour than benefits.

OT for this group but presumably MSFT takes that attitude when producing
new versions of Windows. It makes each new version bigger and slower than
the previous version. They ought to follow the policy of our accountants -
next year's budget will be 5% less than this year's AND you will do 5%
more for the money :)
 
O

Oliver

I would normally do everything "the old way" as you seem to call it because
it gives me control over my code and I can optimise my statements. It may
take a little more time to plan compared to doing it using the designer
method, but in the end I don't really see too much of a benefit in strongly
typed databases. Not optimising code and just assuming that computers are
getting faster is simply sloppy coding practice. I like having a clear data
layer and a clear UI layer.

Anyway I'm not here for a lesson on databases; I think my two questions are
pretty clear and I stated my assumptions.

I am using the visual studio designer to bind to my database, but I need
some finer tuning in the DataSet. I want to log insert and delete statements
so I need to be able to get in there somehow on that level. So I ask once
again; can anyone suggest a way maybe using partial classes?
 
Ad

Advertisements

C

Cor Ligthert[MVP]

Jeff,

You do reminds me to the time it was needed to go ahead a locomotive with a
red flag

But they made trains faster so it became impossible. But maybe they still do
that in the UK

:)

Cor

PS I was often in the UK so I know the answer
 
Ad

Advertisements

J

Jeff Gaines

You do reminds me to the time it was needed to go ahead a locomotive with
a red flag

But they made trains faster so it became impossible. But maybe they still
do that in the UK

We're practising for the Olympics, we can ALL walk faster than the trains
here :)
 

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