Home All Groups Group Topic Archive Search About
Author
1 Nov 2006 6:11 PM
Charles Zhang
I have a "static" datatable in a class and the datatable is loaded by
the type constructor. I want to make the datatable as read only, is it
possible without using events to rollback the changes?

Thanks

Charles Zhang

Author
1 Nov 2006 6:18 PM
Marina Levit [MVP]
By readonly, I take it you mean that no one should be able to modify the
contents of the datatable?

If so, the only way to do that, would be to make it private, and write
methods that are wrappers for the functionality you want to expose. So you
may want to write some Get methods, to get data out of the datatable. But
you wouldn't have any to set the data.

Show quote
"Charles Zhang" <CharlesZhang@newsgroups.nospam> wrote in message
news:OsxueFe$GHA.4348@TK2MSFTNGP04.phx.gbl...
>I have a "static" datatable in a class and the datatable is loaded by the
>type constructor. I want to make the datatable as read only, is it possible
>without using events to rollback the changes?
>
> Thanks
>
> Charles Zhang
>
Author
1 Nov 2006 6:30 PM
Cor Ligthert [MVP]
Marina,

You confuse me with your answer.

In my idea

Making a database table read only is just giving no rights to the user in
the database to change.
Using a DataTable read only is just disable all controls that are binded to
it and not creating procedures around it that use other controls.

And if you don't want to update the database with the datatable. Don't
create an update method.

What do I see wrong?

Cor

Show quote
"Marina Levit [MVP]" <someone@nospam.com> schreef in bericht
news:uYf4wHe$GHA.2328@TK2MSFTNGP02.phx.gbl...
> By readonly, I take it you mean that no one should be able to modify the
> contents of the datatable?
>
> If so, the only way to do that, would be to make it private, and write
> methods that are wrappers for the functionality you want to expose. So you
> may want to write some Get methods, to get data out of the datatable. But
> you wouldn't have any to set the data.
>
> "Charles Zhang" <CharlesZhang@newsgroups.nospam> wrote in message
> news:OsxueFe$GHA.4348@TK2MSFTNGP04.phx.gbl...
>>I have a "static" datatable in a class and the datatable is loaded by the
>>type constructor. I want to make the datatable as read only, is it
>>possible without using events to rollback the changes?
>>
>> Thanks
>>
>> Charles Zhang
>>
>
>
Author
1 Nov 2006 7:47 PM
Marina Levit [MVP]
I understood the question as having a variable of type DataTable, where the
developer cannot change any of the values in that datatable. The developer
can only read values from it.

That way my interpretation of the question. The way the question was
phrased, it was ambigous, and I happen to understand it this way.

If the question was how to not allow the user to make changes to a table,
then of course the answer is very different.

Show quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:Orz9kOe$GHA.3380@TK2MSFTNGP04.phx.gbl...
> Marina,
>
> You confuse me with your answer.
>
> In my idea
>
> Making a database table read only is just giving no rights to the user in
> the database to change.
> Using a DataTable read only is just disable all controls that are binded
> to it and not creating procedures around it that use other controls.
>
> And if you don't want to update the database with the datatable. Don't
> create an update method.
>
> What do I see wrong?
>
> Cor
>
> "Marina Levit [MVP]" <someone@nospam.com> schreef in bericht
> news:uYf4wHe$GHA.2328@TK2MSFTNGP02.phx.gbl...
>> By readonly, I take it you mean that no one should be able to modify the
>> contents of the datatable?
>>
>> If so, the only way to do that, would be to make it private, and write
>> methods that are wrappers for the functionality you want to expose. So
>> you may want to write some Get methods, to get data out of the datatable.
>> But you wouldn't have any to set the data.
>>
>> "Charles Zhang" <CharlesZhang@newsgroups.nospam> wrote in message
>> news:OsxueFe$GHA.4348@TK2MSFTNGP04.phx.gbl...
>>>I have a "static" datatable in a class and the datatable is loaded by the
>>>type constructor. I want to make the datatable as read only, is it
>>>possible without using events to rollback the changes?
>>>
>>> Thanks
>>>
>>> Charles Zhang
>>>
>>
>>
>
>
Author
2 Nov 2006 4:58 AM
Cor Ligthert [MVP]
Marina,

Now I understand what you mean, and I did not see that in advance, however.

From you: the one who is one of the regulars who is the most against
Strongly Typed Datasets in this newsgroup (you are not alone), while this is
in my idea a typical Strongly Typed DataSet answer,

:-)

Cor

Show quote
"Marina Levit [MVP]" <someone@nospam.com> schreef in bericht
news:e6Fs05e$GHA.1224@TK2MSFTNGP04.phx.gbl...
>I understood the question as having a variable of type DataTable, where the
>developer cannot change any of the values in that datatable. The developer
>can only read values from it.
>
> That way my interpretation of the question. The way the question was
> phrased, it was ambigous, and I happen to understand it this way.
>
> If the question was how to not allow the user to make changes to a table,
> then of course the answer is very different.
>
> "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
> news:Orz9kOe$GHA.3380@TK2MSFTNGP04.phx.gbl...
>> Marina,
>>
>> You confuse me with your answer.
>>
>> In my idea
>>
>> Making a database table read only is just giving no rights to the user in
>> the database to change.
>> Using a DataTable read only is just disable all controls that are binded
>> to it and not creating procedures around it that use other controls.
>>
>> And if you don't want to update the database with the datatable. Don't
>> create an update method.
>>
>> What do I see wrong?
>>
>> Cor
>>
>> "Marina Levit [MVP]" <someone@nospam.com> schreef in bericht
>> news:uYf4wHe$GHA.2328@TK2MSFTNGP02.phx.gbl...
>>> By readonly, I take it you mean that no one should be able to modify the
>>> contents of the datatable?
>>>
>>> If so, the only way to do that, would be to make it private, and write
>>> methods that are wrappers for the functionality you want to expose. So
>>> you may want to write some Get methods, to get data out of the
>>> datatable. But you wouldn't have any to set the data.
>>>
>>> "Charles Zhang" <CharlesZhang@newsgroups.nospam> wrote in message
>>> news:OsxueFe$GHA.4348@TK2MSFTNGP04.phx.gbl...
>>>>I have a "static" datatable in a class and the datatable is loaded by
>>>>the type constructor. I want to make the datatable as read only, is it
>>>>possible without using events to rollback the changes?
>>>>
>>>> Thanks
>>>>
>>>> Charles Zhang
>>>>
>>>
>>>
>>
>>
>
>
Author
1 Nov 2006 10:17 PM
Larry Morris
How about something like:

myDataTable.DefaultView.AllowEdit=false;

Show quote
"Charles Zhang" wrote:

> I have a "static" datatable in a class and the datatable is loaded by
> the type constructor. I want to make the datatable as read only, is it
> possible without using events to rollback the changes?
>
> Thanks
>
> Charles Zhang
>
>
Author
2 Nov 2006 2:44 AM
Charles Zhang
That is an interesting idea. My first feeling was: it would not work
since "AllowEdit" only apply to the view not the data table itself.

To make sure, I tried something like:
myDataTable.DefaultView.AllowEdit = false;
myDataTable[0][0] ="Try to Change";
myDataTable.AcceptChanges();

Then I used the debugger to see the value of myDataTable[0][0]
The content of the field was change to "Try to Change"

Thanks

Charles Zhang



Larry Morris wrote:
Show quote
> How about something like:
>
> myDataTable.DefaultView.AllowEdit=false;
>
> "Charles Zhang" wrote:
>
>> I have a "static" datatable in a class and the datatable is loaded by
>> the type constructor. I want to make the datatable as read only, is it
>> possible without using events to rollback the changes?
>>
>> Thanks
>>
>> Charles Zhang
>>
>>
Author
2 Nov 2006 10:38 AM
WenYuan Wang
Hi Charles,
According to your description,
I understand that you want to make the DataTable as read only,
If I misunderstood anything here, please don't hesitate to correct me.

"myDataTable.DefaultView.AllowEdit = false" means that DataGrid or GridView
binding to this DataTable can not Edit.
But you still can edit the rows in DataTable by code.(e.g:
myDataTable[0][0] ="Try to Change";)

So we suggest you can use the method ("DataTable.RejectChanges()") when
there is an event("DataTable.RowChanged") fired.
Such as:
myDataTable.RowChanged += new DataRowChangeEventHandler(dt_RowChanged);
void dt_RowChanged(object sender, DataRowChangeEventArgs e)
        {
            myDataTable.RejectChanges();
        }

But the event "dt_RowChanged" will be fired twice.
The fist time is due to the statement "myDataTable.Rows[0][0] ='Try to
Change'".
And the second time is due to the method "DataTable.RejectChanges()".

If there is any question, please feel free to reply here and I am glad to
work with you.
Wen Yuan
===============================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
===============================
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Author
2 Nov 2006 6:11 PM
Charles Zhang
Thanks.

I was using as DataTable just like an memory array. Since it is
difficult to make it read only, I have decided to store the info as real
array.

Charles Zhang


WenYuan Wang wrote:
Show quote
> Hi Charles,
> According to your description,
> I understand that you want to make the DataTable as read only,
> If I misunderstood anything here, please don't hesitate to correct me.
>
> "myDataTable.DefaultView.AllowEdit = false" means that DataGrid or GridView
> binding to this DataTable can not Edit.
> But you still can edit the rows in DataTable by code.(e.g:
> myDataTable[0][0] ="Try to Change";)
>
> So we suggest you can use the method ("DataTable.RejectChanges()") when
> there is an event("DataTable.RowChanged") fired.
> Such as:
> myDataTable.RowChanged += new DataRowChangeEventHandler(dt_RowChanged);
> void dt_RowChanged(object sender, DataRowChangeEventArgs e)
>         {
>             myDataTable.RejectChanges();
>         }
>
> But the event "dt_RowChanged" will be fired twice.
> The fist time is due to the statement "myDataTable.Rows[0][0] ='Try to
> Change'".
> And the second time is due to the method "DataTable.RejectChanges()".
>
> If there is any question, please feel free to reply here and I am glad to
> work with you.
> Wen Yuan
> ===============================
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ===============================
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
>
Author
6 Nov 2006 11:31 AM
WenYuan Wang
Hi Charles ,

How is it going with the problem?

If there is anything I can help with,
please feel free to post in the newsgroup and we will follow up.
I'm very glad to work with you.

Sincerely,
Wen Yuan

AddThis Social Bookmark Button