I have some data in a DataTable object that I'd like to put into a static
class for the entire app to use, kind of like a cahced global value. The
data in there should not change, but DataTable by default can be changed.
Is there an easy way to make it read only. I can probably create my own
wrapper class to accomplish this but hopefully there is a way to do this
directly on the DataTable.

Thanks in advance for any help
Bob

Re: how to make an object readonly in runtime? by Lucas

Lucas
Mon Aug 16 16:09:46 CDT 2004

" Bob" <bobatkpmg@yahoo.com> wrote in news:OWgP0I9gEHA.3348
@TK2MSFTNGP12.phx.gbl:

> I can probably create my own
> wrapper class to accomplish this but hopefully there is a way to do this
> directly on the DataTable.
>

This might work, try declaring the table as constant and fill the datatable
in the constructor.

Or declare the datatable as private and provide your own methods for
accessing the datatable?



--
Lucas Tam (REMOVEnntp@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/

Re: how to make an object readonly in runtime? by Scott

Scott
Mon Aug 16 16:37:49 CDT 2004

If VB, declare the class members as Shared and the class itself as
NotInheritable. Set up the DataTable in the constructor.


" Bob" <bobatkpmg@yahoo.com> wrote in message
news:OWgP0I9gEHA.3348@TK2MSFTNGP12.phx.gbl...
>I have some data in a DataTable object that I'd like to put into a static
> class for the entire app to use, kind of like a cahced global value. The
> data in there should not change, but DataTable by default can be changed.
> Is there an easy way to make it read only. I can probably create my own
> wrapper class to accomplish this but hopefully there is a way to do this
> directly on the DataTable.
>
> Thanks in advance for any help
> Bob
>
>



Re: how to make an object readonly in runtime? by Jon

Jon
Mon Aug 16 16:40:07 CDT 2004

Scott M. <s-mar@nospam.nospam> wrote:
> If VB, declare the class members as Shared and the class itself as
> NotInheritable. Set up the DataTable in the constructor.

I don't see how that prevents the DataTable's data from changing.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Re: how to make an object readonly in runtime? by Scott

Scott
Mon Aug 16 17:00:47 CDT 2004

"but DataTable by default can be changed"

He could use the constructor to determine what DataTable is in use. Or, he
could build a shared property that creates a DataTable.

"Jon Skeet [C# MVP]" <skeet@pobox.com> wrote in message
news:MPG.1b8b3a10471c2c398b18e@msnews.microsoft.com...
> Scott M. <s-mar@nospam.nospam> wrote:
>> If VB, declare the class members as Shared and the class itself as
>> NotInheritable. Set up the DataTable in the constructor.
>
> I don't see how that prevents the DataTable's data from changing.
>
> --
> Jon Skeet - <skeet@pobox.com>
> http://www.pobox.com/~skeet
> If replying to the group, please do not mail me too



Re: how to make an object readonly in runtime? by Karl

Karl
Mon Aug 16 17:09:54 CDT 2004

Couldn't you return a copy() of the datatable? People would be able to make
changes to the copy of the datatable, but it wouldn't effect the underlaying
table.

Karl

" Bob" <bobatkpmg@yahoo.com> wrote in message
news:OWgP0I9gEHA.3348@TK2MSFTNGP12.phx.gbl...
> I have some data in a DataTable object that I'd like to put into a static
> class for the entire app to use, kind of like a cahced global value. The
> data in there should not change, but DataTable by default can be changed.
> Is there an easy way to make it read only. I can probably create my own
> wrapper class to accomplish this but hopefully there is a way to do this
> directly on the DataTable.
>
> Thanks in advance for any help
> Bob
>
>



Re: how to make an object readonly in runtime? by Bob

Bob
Mon Aug 16 17:32:14 CDT 2004

Ha, I was thinking of this but was looking at the Clone(), which only clones
the schema. Should have eyeballed down a bit further. I'll run some test
on the speed of Copy() vs. creating a brand new DataTable and see if it has
an edge.

Thanks a lot
Bob

"Karl" <none> wrote in message
news:%236Ob1z9gEHA.3348@TK2MSFTNGP12.phx.gbl...
> Couldn't you return a copy() of the datatable? People would be able to
make
> changes to the copy of the datatable, but it wouldn't effect the
underlaying
> table.
>
> Karl
>
> " Bob" <bobatkpmg@yahoo.com> wrote in message
> news:OWgP0I9gEHA.3348@TK2MSFTNGP12.phx.gbl...
> > I have some data in a DataTable object that I'd like to put into a
static
> > class for the entire app to use, kind of like a cahced global value.
The
> > data in there should not change, but DataTable by default can be
changed.
> > Is there an easy way to make it read only. I can probably create my own
> > wrapper class to accomplish this but hopefully there is a way to do this
> > directly on the DataTable.
> >
> > Thanks in advance for any help
> > Bob
> >
> >
>
>



Re: how to make an object readonly in runtime? by Lloyd

Lloyd
Mon Aug 16 18:48:36 CDT 2004

Perhaps you could capture one the "changing" events and then perform a
RejectChanges method to reverse all the changes.

Lloyd Sheen

" Bob" <bobatkpmg@yahoo.com> wrote in message
news:O7O5TE%23gEHA.536@TK2MSFTNGP11.phx.gbl...
> Ha, I was thinking of this but was looking at the Clone(), which only
clones
> the schema. Should have eyeballed down a bit further. I'll run some test
> on the speed of Copy() vs. creating a brand new DataTable and see if it
has
> an edge.
>
> Thanks a lot
> Bob
>
> "Karl" <none> wrote in message
> news:%236Ob1z9gEHA.3348@TK2MSFTNGP12.phx.gbl...
> > Couldn't you return a copy() of the datatable? People would be able to
> make
> > changes to the copy of the datatable, but it wouldn't effect the
> underlaying
> > table.
> >
> > Karl
> >
> > " Bob" <bobatkpmg@yahoo.com> wrote in message
> > news:OWgP0I9gEHA.3348@TK2MSFTNGP12.phx.gbl...
> > > I have some data in a DataTable object that I'd like to put into a
> static
> > > class for the entire app to use, kind of like a cahced global value.
> The
> > > data in there should not change, but DataTable by default can be
> changed.
> > > Is there an easy way to make it read only. I can probably create my
own
> > > wrapper class to accomplish this but hopefully there is a way to do
this
> > > directly on the DataTable.
> > >
> > > Thanks in advance for any help
> > > Bob
> > >
> > >
> >
> >
>
>



Re: how to make an object readonly in runtime? by Jay

Jay
Mon Aug 16 19:21:14 CDT 2004

Bob,
One thing I can think of to approximate a read-only DataTable would be to
handle the DataTable.RowChanging & DataTable.RowDeleting events and raise
exceptions to let the culprits know they shouldn't change the table.

You may be able to handle the events and keep the existing values, but I'm
not sure how well that will work.

Hope this helps
Jay


" Bob" <bobatkpmg@yahoo.com> wrote in message
news:OWgP0I9gEHA.3348@TK2MSFTNGP12.phx.gbl...
> I have some data in a DataTable object that I'd like to put into a static
> class for the entire app to use, kind of like a cahced global value. The
> data in there should not change, but DataTable by default can be changed.
> Is there an easy way to make it read only. I can probably create my own
> wrapper class to accomplish this but hopefully there is a way to do this
> directly on the DataTable.
>
> Thanks in advance for any help
> Bob
>
>



Re: how to make an object readonly in runtime? by Jon

Jon
Tue Aug 17 00:48:05 CDT 2004

Scott M. <s-mar@nospam.nospam> wrote:
> "but DataTable by default can be changed"
>
> He could use the constructor to determine what DataTable is in use. Or, he
> could build a shared property that creates a DataTable.

But when the DataTable has been created, it can be changed. That's the
point of his question.

Either he doesn't provide direct access to the DataTable in the first
place (which would no doubt mean duplicating all its read-only
functionality - argh) or he has to unfortunately take the hit that
DataTables are read-write.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Re: how to make an object readonly in runtime? by Bob

Bob
Tue Aug 17 10:01:41 CDT 2004

I did some test and Copy() does meet my goal of caching the data to improve
speed. Rendering the same page takes anywhere from below 1 to 10
milliseconds vs. 10 to 30 milliseconds if creating the DataTable from an XML
string (Reading into DataSet). So it's a very good result.

Also thanks for all the other suggestions on handling events. I think that
would certianly be useful in some other situations.

Bob

" Bob" <bobatkpmg@yahoo.com> wrote in message
news:O7O5TE%23gEHA.536@TK2MSFTNGP11.phx.gbl...
> Ha, I was thinking of this but was looking at the Clone(), which only
clones
> the schema. Should have eyeballed down a bit further. I'll run some test
> on the speed of Copy() vs. creating a brand new DataTable and see if it
has
> an edge.
>
> Thanks a lot
> Bob
>
> "Karl" <none> wrote in message
> news:%236Ob1z9gEHA.3348@TK2MSFTNGP12.phx.gbl...
> > Couldn't you return a copy() of the datatable? People would be able to
> make
> > changes to the copy of the datatable, but it wouldn't effect the
> underlaying
> > table.
> >
> > Karl
> >
> > " Bob" <bobatkpmg@yahoo.com> wrote in message
> > news:OWgP0I9gEHA.3348@TK2MSFTNGP12.phx.gbl...
> > > I have some data in a DataTable object that I'd like to put into a
> static
> > > class for the entire app to use, kind of like a cahced global value.
> The
> > > data in there should not change, but DataTable by default can be
> changed.
> > > Is there an easy way to make it read only. I can probably create my
own
> > > wrapper class to accomplish this but hopefully there is a way to do
this
> > > directly on the DataTable.
> > >
> > > Thanks in advance for any help
> > > Bob
> > >
> > >
> >
> >
>
>



Re: how to make an object readonly in runtime? by Ignacio

Ignacio
Tue Aug 17 10:21:17 CDT 2004

Hi Bob,


Did you check if DataView with AllowEdit/Add/Delete disable do what you
want?

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

" Bob" <bobatkpmg@yahoo.com> wrote in message
news:OWgP0I9gEHA.3348@TK2MSFTNGP12.phx.gbl...
> I have some data in a DataTable object that I'd like to put into a static
> class for the entire app to use, kind of like a cahced global value. The
> data in there should not change, but DataTable by default can be changed.
> Is there an easy way to make it read only. I can probably create my own
> wrapper class to accomplish this but hopefully there is a way to do this
> directly on the DataTable.
>
> Thanks in advance for any help
> Bob
>
>



Re: how to make an object readonly in runtime? by William

William
Tue Aug 17 10:40:36 CDT 2004

I might create an object/class with public properties for each column
instead of a DataTable. Then just clone that or make the Properties read
only. You could also include a GetDataTable() method that constructs a
DataTable from the object - so you have the flexability of Object, or
DataTable, or both depending on the needs.

--
William Stacey, MVP

" Bob" <bobatkpmg@yahoo.com> wrote in message
news:OWgP0I9gEHA.3348@TK2MSFTNGP12.phx.gbl...
> I have some data in a DataTable object that I'd like to put into a static
> class for the entire app to use, kind of like a cahced global value. The
> data in there should not change, but DataTable by default can be changed.
> Is there an easy way to make it read only. I can probably create my own
> wrapper class to accomplish this but hopefully there is a way to do this
> directly on the DataTable.
>
> Thanks in advance for any help
> Bob
>
>