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.
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.