How to disable expression computation

  • Thread starter Andrzej Kaczmarczyk
  • Start date
A

Andrzej Kaczmarczyk

Hi,

I have a DataTable, and a DataColumn, with an expression set.
let say it is [Price] * [Quantity] expression

I'd like to change the value in some rows, without removing the computed .

column.Expression = null

removes all computed values (actually it just recompute the colum).

trying to do table.Rows[0][column] = "new value";

claims "The column is read only".

anything to do with this except manual copying to another column? or
computing by hand?

CUIN Kaczy
 
M

Miha Markic [MVP C#]

Hi Andrzej,

I would go manual as I don't think that you'll be able to find a way around.
 
M

Marina

Let's call the computed column Column1. Add a Column2, in which you set the
value manually. You only do that for rows that need it, and leave it NULL
for the others.

Then you can have a 3rd computed column, that returns Column2 if it is not
NULL, and Column1 otherwise. That way you can use the 3rd column in
databinding or what not. I think the expressions support an IsNull, so
hopefully you can do this.
 
A

Andrzej Kaczmarczyk

U¿ytkownik "Marina said:
Let's call the computed column Column1. Add a Column2, in which you set
the value manually. You only do that for rows that need it, and leave it
NULL for the others.

Then you can have a 3rd computed column, that returns Column2 if it is not
NULL, and Column1 otherwise. That way you can use the 3rd column in
databinding or what not. I think the expressions support an IsNull, so
hopefully you can do this.

Excellent one,
thanks.

Actually I did as suggested and computed the values myself (BeginLoad, set
the values, EndLoad, AcceptChanges on dataTable) and it turned out to be
fast enough ( I needed somewhere around 10000 calculations and on my comp
they were done less then second)
but I'll keep in mind you solution

CUIN Kaczy
Andrzej Kaczmarczyk said:
Hi,

I have a DataTable, and a DataColumn, with an expression set.
let say it is [Price] * [Quantity] expression

I'd like to change the value in some rows, without removing the computed
.

column.Expression = null

removes all computed values (actually it just recompute the colum).

trying to do table.Rows[0][column] = "new value";

claims "The column is read only".

anything to do with this except manual copying to another column? or
computing by hand?

CUIN Kaczy
 
M

Miha Markic [MVP C#]

Hi Andrzej,

Marina's solution is certainly an interesting one.
However, if you go manually you have total control over the process and
speed is probably better compared to expressions.
Plus you avoid certain problems with expressions (when editing data, when
saving data, etc.)

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Andrzej Kaczmarczyk said:
U¿ytkownik "Marina said:
Let's call the computed column Column1. Add a Column2, in which you set
the value manually. You only do that for rows that need it, and leave it
NULL for the others.

Then you can have a 3rd computed column, that returns Column2 if it is
not NULL, and Column1 otherwise. That way you can use the 3rd column in
databinding or what not. I think the expressions support an IsNull, so
hopefully you can do this.

Excellent one,
thanks.

Actually I did as suggested and computed the values myself (BeginLoad, set
the values, EndLoad, AcceptChanges on dataTable) and it turned out to be
fast enough ( I needed somewhere around 10000 calculations and on my comp
they were done less then second)
but I'll keep in mind you solution

CUIN Kaczy
Andrzej Kaczmarczyk said:
Hi,

I have a DataTable, and a DataColumn, with an expression set.
let say it is [Price] * [Quantity] expression

I'd like to change the value in some rows, without removing the computed
.

column.Expression = null

removes all computed values (actually it just recompute the colum).

trying to do table.Rows[0][column] = "new value";

claims "The column is read only".

anything to do with this except manual copying to another column? or
computing by hand?

CUIN Kaczy
 
C

Cor Ligthert [MVP]

Miha,
Marina's solution is certainly an interesting one.
However, if you go manually you have total control over the process and
speed is probably better compared to expressions.
Plus you avoid certain problems with expressions (when editing data, when
saving data, etc.)

I only write, I don't agree that with you, I prefer the method Marina has
given.

I would have given a same kind as answer if she had not done that already.

:)

Cor
 
C

Cor Ligthert [MVP]

Miha,
Obviously, you haven't used expressions for real ;-)

You would probably sometimes have seen (especially in the short future),
that I have written that I *hate* expressions, where my most used sample is
than the expression from AdoNet and after that SQL.

I have never used that *compute* and almost any expression beside very short
ones (I have once made a sample for somebody using that compute) even the
samples you give often with the *like* I try to avoid.

However, with the datagrid (strugling with that sample) there are in my
opinon not much efficient alternatives than as Marina has showed.

Again just my opinion.

Cor
 
M

Miha Markic [MVP C#]

However, with the datagrid (strugling with that sample) there are in my
opinon not much efficient alternatives than as Marina has showed.

Manual calculation is more efficient, powerful and manageable alternative.
 
C

Cor Ligthert [MVP]

Miha,
Manual calculation is more efficient, powerful and manageable alternative.

--

As I always write, in my idea have we both the right to have our own opinon.

Where I started in this thread to you with, telling that I did *prefer* the
method that Marina was showing.

By the way, do you know why I hate expressions in general (not directly
talking about the ones in AdoNet because I told you that I try to avoid them
so I can not clearly tell that).

They seems to me sometimes be made on the slang of the country where they
are created. And if that is the USA even that in the seperated states. While
the algabraic part is in my idea sometimes real self created by the creator.

Which means that I always am lucky when I don't know a used word, that my
dictionary shows me the right translation of that (my English translation
dictionary is as probably most in Europe based on UK English) and for the
algabraic part it is than try and hope no error.

:)

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top