?
Solved

Adding a row to Datatable - urgent help needed

Posted on 2010-11-21
4
Medium Priority
?
348 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 2000 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

Python: Series & Data Frames With Pandas

Learn the basics of Python’s pandas library of series & data frames and how we can use these tools for data manipulation.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

743 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