How to persist a COMPUTED column in a data table??

M

Mo

Hello...
I have two columns in a datatable. column calcCol1 and Col1. When I loop through the records to copy data from the computed column to the original column it gives an error saying that there is no data. (although I know there is).
I loop as follows

dim dr as datarow
for each row in dtable
dr("Col1") = dr("CalcCol1")
next

what I am doing wrong?
thanks in advance.

___
Newsgroups brought to you courtesy of www.dotnetjohn.com
 
C

Cor

Hi Mo,
dim dr as datarow
for each row in dtable
dr("Col1") = dr("CalcCol1")
next

what I am doing wrong?
thanks in advance.
I don't know, however when I do this I have to do
dim dr as datarow
for each dr in dtable.rows
.....
next

Maybe you can try that?
:)
Cor
 
W

William Ryan eMVP

Mo:

Doing this is probably going to cause you another problem.

Say that dr1 = 5 and that dr11 = 25 (assume that dr11's formula is dr1 * 5).
Ok, you move 25 to dr1, now dr11 will be 125 b/c the value has changed.
However, what specific exception are you getting. I've used the exact same
code and it's behaving exactly as I expected. If you are getting an
argument exception, it's probably because you have a Null value in there
somewhere or a value that can't be converted. If you are getting an
Evaluate Exception , it's probably b/c a column name is mispelled or
incorrect. Here's code I used to do this and it works as expected. If you
can post the column names and the exact exception message, may be able to
be of more help:

DataTable dt1 = new DataTable();

da.Fill(dt1);

DataColumn dcc = new DataColumn( "System.Int32");

dcc.Expression = "Id * Department";

dt1.Columns.Add(dcc);

foreach(DataRow dro in dt1.Rows)

{

dro[0] = dro[2];

}



Bill

Mo said:
Hello...
I have two columns in a datatable. column calcCol1 and Col1. When I loop
through the records to copy data from the computed column to the original
column it gives an error saying that there is no data. (although I know
there is).
 

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