Sunday, 15 January 2012

vb.net - DataTable Column.Expression Throw Error -



vb.net - DataTable Column.Expression Throw Error -

i have info table contains few row below

ch1 ch2 ch3 ch4 ch5 1 2 1 2 3 3 3 1 2 3 3 3 1 1 2 1 3 3 3 3 1 2 3 3 0 3 3 1 2 0 3 3 1 1 2

then seek add together new column like

dim col new datacolumn("vch1", gettype(decimal),"(ch1+ch2+ch3)/ch5") dtreadings.columns.add(col)

at time give me error : attempted split zero. because of ch5 have 0 values, need add together dynamic column different look @ run time ,how avoid such type of error thought please help.

expression value not fixed,user create look dynamic column. not handle split 0 error ,to handle type of computing error

the expression syntax allow utilize of iif statement build datacolumn using kind of syntax expression

col = new datacolumn("vch1", gettype(decimal), "iif(ch5 = 0, 0, (ch1+ch2+ch3)/ch5)")

of course, beingness look string property build look dynamically based on particular requirement have @ moment. iif or isnull build string on fly before adding column. pseudocode

dim currentexpression string = buildcurrentexpression() col = new datacolumn("vch1", gettype(decimal), currentexpression)

vb.net winforms datatable

No comments:

Post a Comment