Solved

DataTable Validation

Posted on 2014-02-20
4
257 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

810 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