Improve company productivity with a Business Account.Sign Up

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

DataTable Validation

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
Easwaran Paramasivam
Asked:
Easwaran Paramasivam
  • 2
  • 2
2 Solutions
 
HugoHiaslCommented:
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
 
Easwaran ParamasivamAuthor Commented:
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
 
HugoHiaslCommented:
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
 
Easwaran ParamasivamAuthor Commented:
Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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