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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:09:34+00:00 2026-05-31T18:09:34+00:00

Design of SQL Table Users: Columns: ID(Primary Key), Name, Age, Zip. I am displaying

  • 0

Design of SQL Table Users:

Columns:
ID(Primary Key),
Name,
Age,
Zip.

I am displaying a grid view onto the asp.net application with the above table details which i am able to do now.Right now i am displaying only Name,age,zip on to the gridview.There is a form below the gridview where user can enter the data and save back to the DB.Here i am able to enter name,age,zip to the database and i am able to see the changes in the gridview.

So when i enter a duplicate name its not saving to the database as expected,at this point i have to show some thing to the user that the name already exists .

Here is my code in c#:

try
{
    param[0] = new SqlParameter("@Name", SqlDbType.NVarChar);
    param[0].Value = txtName.Text;
    param[1] = new SqlParameter("@Age", SqlDbType.NVarChar);
    param[1].Value = txtAge.Text;
    param[2] = new SqlParameter("@Zip", SqlDbType.int);
    param[2].Value = txtZip.Text;
    DBHelper helper = new DBHelper();
    helper.ExecuteNonQuery(CommandType.StoredProcedure, "Add_Users", param);
    GridView1.DataBind();
}
catch (Exception ex)
{

}

I am expecting an sql exception in the above code where i am planning to notify the user .But i am unable to get any exception .

Can some one suggest where i am missing the catch here.

I just want to notify the user that the name is already taken eventually.

  • 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-31T18:09:35+00:00Added an answer on May 31, 2026 at 6:09 pm

    Using exceptions is a bad design in this case. This is not an error, but a predictable behaviour of your program.

    One of the easiest ways to solve the problem is doing a select at the end of the Add_Users stored procedure that returns 1 or 0, depending on the success or failure, and using ExecuteScalar insead of ExecuteNonQuery to get the result.

    You can also use a return in the stored procedure, and take back that value (geenrally as a special output parameter), but I don’t know if the DbHelper allows you to do so.

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

Sidebar

Related Questions

I have this DB design: CREATE TABLE report ( ID MEDIUMINT PRIMARY KEY NOT
I am using a asp.net grid view to load data from my sql data
I'm learning about table design in SQL and I'm wonder how to create a
In this sql: SELECT s.*, u.id, u.name FROM shops s LEFT JOIN users u
Do you know a good source to learn how to design SQL solutions? Beyond
I need to design database for SQL Server, is there any MySQL workbench like
We've an SQL Server DB design time scenario .. we've to store data about
I'm using LINQ to SQL classes in a project where the database design is
This is a design question, I noticed that by time by LINQ-to-SQL Context gets
I'm having problems with design correct SQL query. I'm tired like a hell today,

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.