DataColumn.Expression complex calculations

G

Guest

Hi.
Does anybody know how to perform complex calculations using the
DataColumn.Expression property?
Specifically, I'm trying to calculate the difference between a DateTime
column and the current date:
DateTime.Now.Subtract(certainDate).TotalDays

Is there a way to integrate custom functions in this property?
 
M

Miha Markic [MVP C#]

Hi Amir,

I think that it is best to manually perform such calculations in this case.
Refresh them in ColumnChanged event and do an DataRowAcceptChanges if he row
wasn't modified before.
 
C

Cor Ligthert

Amir,

In my opinion is the expression not to for doing *complex* calculations.

http://msdn.microsoft.com/library/d...fSystemDataDataColumnClassExpressionTopic.asp

On this page is only with this sample given how to use dates
"Birthdate < #1/31/82#"

Be aware that because every thing in dotNet is nicely globalized done, you
have to investigage how it has to be used with computers outside the USA,
because this is a typical USA notation and I don't know if it is for
computers (beside English speaking Canada) in the rest of the world
accoording those culture/language notations..

I hope this helps,

Cor
 
V

Val Mazur \(MVP\)

Hi,

What you could do is to catch an event of the DataTable when DataRow inside
of it has been changed and calculate new date inside of this event. Then
assign value to the column. At least it will work in all the cases when row
was modified
 

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