Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8521219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:45:35+00:00 2026-06-11T06:45:35+00:00

In our application, we are adding a row to a datatable. I would like

  • 0

In our application, we are adding a row to a datatable. I would like to validate the row before it is added to the table, and if the data doesn’t meet business requirements, the row does not get added.
I would think RowChanging even is where I need to add validation code. However, how do I prevent the row from being added to the DataTable?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T06:45:37+00:00Added an answer on June 11, 2026 at 6:45 am

    I think the only way you can stop a row from being added in the RowChanging event handler is to throw an Exception:

    if (e.Action == DataRowAction.Add) {
        if (e.Row["SomeColumn"].ToString() == "AnInvalidValue") {
            throw new InvalidOperationException("You can't do that.");
        }
    }
    

    You’d obviously have to catch this exception and handle it gracefully.

    A better approach would be to do your validation in the UI before attempting to add the new DataRow.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like the next update of our C# application to be the last
Our application downloads data from the internet using RSS but is having connection problems
Our application currently stores bunch of configuraton & application specific data to files on
We are adding a couple pages to our application that don't need to be
I'm loading user controls in a specific grid in our application and I'm adding
I would like to simulate shortcuts for a remote control feature of our Windows
I am considering adding LocalDB for data storage to my application. Background: 1) My
My company is adding some rich calendar functionality to our Swing application. We want
We have a calendar in our web application. Events can be added to the
I am currently adding exception management inside of our application. In the application I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.