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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:30:15+00:00 2026-06-05T22:30:15+00:00

i have a problem with auto incremental primary keys.. when im adding a student

  • 0

i have a problem with auto incremental primary keys..

when im adding a student to my database, i can add the same student over and over again because the primary key of student is auto incremental so it is, of course, never repeated, i need to verify that the SSN of the student does not already exist in the database before inserting.

how can i do that on mvc3?? (im totally new in .net and mvc3)

my code for create in the student controller is:

[HttpPost]
    public ActionResult Create(Alumno alumno)
    {
        try
        {
            using (var db = new administracionEntities())
            {
                db.Alumno.Add(alumno);
                db.SaveChanges();
            }
            return RedirectToAction("Index");
        }
        catch
        {
            return View();
        }
    }
  • 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-05T22:30:16+00:00Added an answer on June 5, 2026 at 10:30 pm

    before you insert check if input alumno.ssn doesnot exist like

    db.Alumno.where(a=> a.ssn == alumno.ssn).Any()
    

    if this returns true, then there exists a ssn in database.

    There are different ways in which you can achieve this in MVC.In one of which, You can have this call in a separate call to controller than in Create Action. May be you can check if duplicate SSN exists through JQuery.Ajax call on SSN textbox blur event on client side.

    $.ajax({
       type: "Get",
       url: "StudentController/DoesSSNExist",
       data: "ssn=#", 
       success: function(msg){
           if(msg)
            alert('ssn already exists');
       }
    

    This is controller action

    public bool DoesSSNExist(string ssn)
    {
        return db.Alumno.where(a=> a.ssn == ssn).Any()
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with MySql primary keys, it's for my project i'm working
Problem: When I use an auto-incrementing primary key in my database, this happens all
I have two tables with the exact same columns. Both have primary identity keys
I have a problem when using foreign keys and primary keys in MySQL datable.
I have a big problem. I use excel auto filter function, at the end
I have problem SIMILAR to preventing form data reposting, but not quite the same
I have a problem to add a Foreign key to a table. I have
We have a table, with an auto-increment int primary key, whose max value is
I have a problem of structure for my database. I want to know why
We use Guids as primary keys for entities in the database. Traditionally, we've followed

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.