Solved

DataTable Validation

Posted on 2014-02-20
4
259 Views
Last Modified: 2014-02-20
I've a datatable which has many columns. The column value of Qty should be
Column value of TotalValue devided by SingleValue column. How to achive that validation? Please assist.
0
Comment
Question by:Easwaran Paramasivam
  • 2
  • 2
4 Comments
 
LVL 12

Assisted Solution

by:HugoHiasl
HugoHiasl earned 300 total points
ID: 39873135
You need to use Expression property of the column.

Find an example here:

http://www.codeproject.com/Articles/447249/Calculated-Columns-in-NET-DataTables-Csharp
0
 
LVL 16

Author Comment

by:Easwaran Paramasivam
ID: 39873210
I look for already available values in the table are correct or not. That should be entered by user. If not I need to throw validation message. Kindly suggest solution.
0
 
LVL 12

Accepted Solution

by:
HugoHiasl earned 300 total points
ID: 39873253
You can use a foreach loop and loop through all the DataRows

Lets assume you cols in the table are 3,4,5

bool validationFailed = true;

foreach{DataRow row in dt.Rows) {

    if(row[5] != row[4] / row[3]) {
        validationFailed = false;
    }
}

Now you can give a validation message. If you need a dynamic column name resolition the loop through the dt.Columns array and get the indexes of the columns from there.
0
 
LVL 16

Author Closing Comment

by:Easwaran Paramasivam
ID: 39876002
Thanks.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

820 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