Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 358
  • Last Modified:

Adding a row to Datatable - urgent help needed

Hi,
I have a datatable with 2 columns "LONG" and "SHORT". before binding to grid, i need to add one more column "NET" .
NET = LONG - SHORT.
I need to calculate NET value by substracting short from long and I have to handle NULL values too if in case short or long is null.

Finally, my datatable shd be

long      short     Net
2              1          1
3               3          0

Please someone help me... I tried dng this bt I am missing something. i am not getting exaclty the way i am looking for. Please help me...

Thanks...

0
gautam_reddyc
Asked:
gautam_reddyc
  • 3
1 Solution
 
Carl TawnSystems and Integration DeveloperCommented:
Should be easy enough. Try:

YourDataTable.Columns.Add(new DataColumn("Net", typeof(int), "long - short"));

Open in new window

0
 
gautam_reddycAuthor Commented:
Hi carl tawn,

This will work if you have only one row. What if you have mutliple rows of long and short... If we do foreach for all rows, only first time we can add column. In the next statement we will get an error saying already column  exists.

Please help me how to do this...
0
 
gautam_reddycAuthor Commented:
sorry, my previous comment was wrong...
my question is: If "LONG" or "Short" values are NULL in database, the datatable is coming with empty row. In that case it's not working. In other words,
for ex: Long value is 2 and short is NULL in databse.. so in datatbale it is empty.. In that case NET is also coming as empty instead of 2 which is Long value... How to handle NULL values.. Please help me...
0
 
gautam_reddycAuthor Commented:
thanks... it worked.. I am explicitly handling the NULL values...
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now