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 12 1941
" Bob" <bo*******@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 (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying. http://members.ebay.com/aboutme/coolspot18/
If VB, declare the class members as Shared and the class itself as
NotInheritable. Set up the DataTable in the constructor.
" Bob" <bo*******@yahoo.com> wrote in message
news:OW**************@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
Scott M. <s-***@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 - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
"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]" <sk***@pobox.com> wrote in message
news:MP***********************@msnews.microsoft.co m... Scott M. <s-***@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 - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
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" <bo*******@yahoo.com> wrote in message
news:OW**************@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
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:%2****************@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" <bo*******@yahoo.com> wrote in message news:OW**************@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
Perhaps you could capture one the "changing" events and then perform a
RejectChanges method to reverse all the changes.
Lloyd Sheen
" Bob" <bo*******@yahoo.com> wrote in message
news:O7***************@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:%2****************@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" <bo*******@yahoo.com> wrote in message news:OW**************@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
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" <bo*******@yahoo.com> wrote in message
news:OW**************@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
Scott M. <s-***@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 - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
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" <bo*******@yahoo.com> wrote in message
news:O7***************@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:%2****************@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" <bo*******@yahoo.com> wrote in message news:OW**************@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
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" <bo*******@yahoo.com> wrote in message
news:OW**************@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
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" <bo*******@yahoo.com> wrote in message
news:OW**************@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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Kenneth Baltrinic |
last post by:
I am getting the following error when deserializing an object that has a couple of dozen dependant objects in its object graph. Anyone who can suggest where I might begin to look to resolve problem...
|
by: Vani Murarka |
last post by:
Hi Everyone,
Does .NET offer any collection class which will give me objects last
*accessed* such that I may build a least-recently-used cache that
kills off objects that haven't been used for...
|
by: Danielb |
last post by:
I need to create a read-only copy of Object X at run time, I know how
to find the type of Object X (using GetType) but how do I go about
creating a readonly copy of X?
What I want to do is this:...
|
by: GP |
last post by:
Is it possible to iterate through all the controls collection and make the
textboxes alone as read only.I don't see a readonly property for the
Control.Can some one help me in this context?
I...
|
by: Phillip Galey |
last post by:
I have an object called Place which contains only string properties and has
the <Serializable()> flag before the class name declaration. I also have a
collection object called Places, which is...
|
by: Random |
last post by:
How can I use reflection (or some other method) to find the type of an
object that has been passed in to my method under an interface definition?
I try to use GetType, but that won't work.
|
by: Andrus |
last post by:
I'm implementing entity object which should populate its properties from
database when property is first referenced.
In RDL reports I use object properties like
MyObject.MyProperty
MyObject...
|
by: Anthony Paul |
last post by:
Hello everyone!
Let's say that I would like a generic type that supports Min/Max
properties and can be double or integer or even datetime if need be,
something flexible.
So I go about...
|
by: Anthony Paul |
last post by:
Let's say that I would like a generic type that supports Min/Max
properties and can be double or integer or even datetime if need be,
something flexible.
So I go about creating the following...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |