Solved

Adding a row to Datatable - urgent help needed

Posted on 2010-11-21
4
317 Views
Last Modified: 2013-12-17
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
Comment
Question by:gautam_reddyc
  • 3
4 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 34183894
Should be easy enough. Try:

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

Open in new window

0
 

Author Comment

by:gautam_reddyc
ID: 34184610
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
 

Author Comment

by:gautam_reddyc
ID: 34184659
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
 

Author Closing Comment

by:gautam_reddyc
ID: 34184920
thanks... it worked.. I am explicitly handling the NULL values...
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now