Question how can add a column's value to use in an expression of another datatable's column

pooya1072

Well-known member
Joined
Jul 5, 2012
Messages
84
Programming Experience
Beginner
hi
i use 3 datatable in my form named DT1 , DT2 and DT3 than each datatable has one column named "Value1" , "Value2" and "Value3"
i want to use values of columns from DT2 and DT3 to use in expression of DT1 columns.
please look at the examples :
i want a thing like this :
VB.NET:
DT1.Columns("Value1").Expression=( DT2.Columns("Value2") + DT3.Columns("Value3"))
so if i can do this , in each row of dt2 or dt3 , if i change the value of the cells , then the value of the cells of dt1 that their column name is "Value1" will change.
i mean :
VB.NET:
for example :

[FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]dt2.Rows(0).Item("Value2")=125
[FONT=Consolas][SIZE=2]dt3.Rows(0).Item("Value3")=25
[/SIZE][/FONT]
then :

[FONT=Consolas][SIZE=2]dt1.Rows(0).Item("Value1")=150[/SIZE][/FONT]

[/SIZE][/FONT][/SIZE][/FONT]
how can i do this?
 
Have you read the documentation for the DataColumn.Expression property? If not, why not? You should do so right now and pay specific attention to the section on 'Parent/Child Relation Referencing'. As it says, the only way that you can use other DataTables in an Expression is if they are all in the same DataSet and it contains DataRelations between them. If there is no explicit relation then how would the expression know which row of the other table to use to get the values for each row of the current table?
 
Back
Top