PC Review


Reply
Thread Tools Rate Thread

DataSet and DataGridView

 
 
Oliver
Guest
Posts: n/a
 
      6th Apr 2009
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.
 
Reply With Quote
 
 
 
 
Oliver
Guest
Posts: n/a
 
      6th Apr 2009
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.
 
Reply With Quote
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      6th Apr 2009
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

"Oliver" <(E-Mail Removed)> wrote in message
news:722DB8D8-63D1-4E47-AD69-(E-Mail Removed)...
> 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.


 
Reply With Quote
 
Jeff Gaines
Guest
Posts: n/a
 
      6th Apr 2009
On 06/04/2009 in message <(E-Mail Removed)> Cor
Ligthert[MVP] wrote:

>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 :-)

--
Jeff Gaines
Damerham Hampshire UK
 
Reply With Quote
 
Oliver
Guest
Posts: n/a
 
      6th Apr 2009
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?
 
Reply With Quote
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      6th Apr 2009
Punch cards


"Oliver" <(E-Mail Removed)> wrote in message
news:4E96FE0F-64E6-4A29-B597-(E-Mail Removed)...
>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?


 
Reply With Quote
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      6th Apr 2009
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

"Jeff Gaines" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On 06/04/2009 in message <(E-Mail Removed)> Cor
> Ligthert[MVP] wrote:
>
>>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 :-)
>
> --
> Jeff Gaines
> Damerham Hampshire UK


 
Reply With Quote
 
Jeff Gaines
Guest
Posts: n/a
 
      6th Apr 2009
On 06/04/2009 in message <(E-Mail Removed)> Cor
Ligthert[MVP] wrote:

>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 :-)

--
Jeff Gaines
Damerham Hampshire UK
 
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
DataSet into DataGridView Scott Spence Microsoft VB .NET 2 7th Jan 2010 08:36 PM
Dataset's - datagridview help Tony M Microsoft VB .NET 1 27th Aug 2008 06:09 PM
How put a Dataset in a Datagridview Freddy Coal Microsoft VB .NET 3 27th Oct 2007 06:48 AM
dataGridView + dataSet in ADO.NET 2.0 =?Utf-8?B?RnJpZWRoZWxtIERyZWNrdHJhaA==?= Microsoft ADO .NET 2 9th Dec 2005 08:29 PM
how to get the data from the datagridview into the dataset cEciLlE Microsoft ADO .NET 0 18th Jan 2005 03:37 AM


Features
 

Advertising
 

Newsgroups
 


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