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 817889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:03:48+00:00 2026-05-15T02:03:48+00:00

HI.I searched this question inform and I found solution to change column property Unique

  • 0

HI.I searched this question inform and I found solution to change column property Unique Index.Now If I try to insert same record cmd.ExecuteNonQuery() gives error that record exist ,but how can use this exception to give user a message that record exist and must enter new one ? I am trying to make some thing like

if(cmd.ExecuteNonQuery() !=true )
{
 MessageBox.Show("User Exists");
}

But I dont know what returns cmd.ExecuteNonQuery() ?

Or I must get records using reader in table and compare them with text in Textfiel?

  • 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-05-15T02:03:49+00:00Added an answer on May 15, 2026 at 2:03 am

    You can put a try catch block around the block of code you have and then look at the exception type and then instead of using Exception in the catch you can use the explicit exception you are trying to catch for.

    try
    {
      cmd.ExecuteNonQuery();
    }
    catch(Exception ex)
    {
      ex.Type.ToString(); //this will give you the type of exception.
    }
    

    Now once you know what the exception is you can catch only that one and inform the user like the following.

    try
    {
      cmd.ExecuteNonQuery();
    }
    catch(RecordExhistsException ex)
    {
      MessageBox.Show("Duplicate Record");
    }
    

    Enjoy!

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

Sidebar

Related Questions

I searched and found this question but did not like the answer. Is there
I have searched for topics specifically to this question but have not found anything
I found this question while i searched the usage of metaclass in python.It's a
I have searched this question, and found an answer in MySQL but this is
In this question I have searched for a simple solution to unblock files. Thanks
I searched the Web about this question but I found nothing: What is the
I faced this question in interview. When I searched on internet I found different
I searched the web but haven't found a real good answer for this question..
I searched SO and found this question , but it's not quite what I'm
ive searched this question on google and i've found many answers but none of

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.