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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:12:59+00:00 2026-06-13T15:12:59+00:00

i am working on an airline reservation system everything compiled nicely…a user is supposed

  • 0

i am working on an airline reservation system everything compiled nicely…a user is supposed to register to the site then check available flights after that the user can book a flight,but i am having problems when it comes to booking a flight the values can not be inserted in the database and there is an error popping up saying

SqlException was unhandled by user code
Violation of PRIMARY KEY constraint 'PK_Plist'. Cannot insert duplicate key in object 'dbo.Plist'.
The statement has been terminated.

what is wrong or what am i doing that is not right
this is my code and an exception is flashing on this code

int i = cmd.ExecuteNonQuery();

the full code

protected void Button1_Click1(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(constring);
        SqlCommand cmd = new SqlCommand();
        cmd.CommandType = CommandType.Text;
        cmd.Connection = con;
        con.Open();
        cmd.CommandText = "select flightid from schedule where flightid='" + DropDownList1.Text + "' and Flightname='" + DropDownList2.Text + "' and Fromstation='" + DropDownList3.Text + "' and Tostation='" + DropDownList4.Text + "' and dateandtimings='" + DropDownList6.Text + "'";
        SqlDataAdapter da = new SqlDataAdapter();
        da.SelectCommand = cmd;
        DataSet ds = new DataSet();
        da.Fill(ds, "emp");
        if (ds.Tables["emp"].Rows.Count > 0)
        {

            cmd.CommandText = "insert into Plist(Pid,passengername,flightid,Flightname,Fromstation,Tostation,category,Dateandtimings) values('" + Autonumber() + "','" + TextBox1.Text + "','" + DropDownList1.Text + "','" + DropDownList2.Text + "','" + DropDownList3.Text + "','" + DropDownList4.Text + "','" + DropDownList5.Text + "','" + DropDownList6.Text + "')";
            int i = cmd.ExecuteNonQuery();
            cmd.CommandText = "update pid set pid='" + Autonumber() + "'";
            int k = cmd.ExecuteNonQuery();
            if (DropDownList5.Text == "Firstclass")
            {
                cmd.CommandText = "update schedule set Firstclass=Firstclass-1 where flightid='" + DropDownList1.SelectedValue + "'";
                int j = cmd.ExecuteNonQuery();
            }
            else if (DropDownList5.Text == "Bussinessclass")
            {
                cmd.CommandText = "update schedule set Bussinessclass=Bussinessclass-1 where flightid='" + DropDownList1.SelectedValue + "'";
                int j = cmd.ExecuteNonQuery();


            }
            else
            {
                cmd.CommandText = "update schedule set Economicclass=Economicclass-1 where flightid='" + DropDownList1.SelectedValue + "'";
                int j = cmd.ExecuteNonQuery();
            }
            if (i > 0)
            {
                Label.Visible = true;
                Label.Text = "success";
            }

            else
            {
                Label.Visible = true;
                Label.Text = "error";
            }

            Label16.Visible = true;
            Label16.Text = "Your Ticket ID is " + a;
            con.Close();
        }
        else
        {
            Label16.Visible = true;
            Label16.Text = "There is no flight with these details so please check flight schedule and submit your request";
        }

    }
    protected void SqlDataSource4_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
    {

    }
    protected void SqlDataSource5_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
    {

    }
}
  • 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-13T15:13:00+00:00Added an answer on June 13, 2026 at 3:13 pm

    You are trying to insert a duplicate primary key into the table Plist. The primary key must be unique. I looks like this autonumber method you are using is no good. You can change the PID column so it is an identity column. With an identity column sql server will give you a unique sequential number for each record you insert.

    SQL Identity
    http://msdn.microsoft.com/en-us/library/ms186775.aspx

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

Sidebar

Related Questions

As a user, I generally don't like working with calendar GUI (e.g. on airline
I'm working with airline data, so I have a query like this SELECT Invoices.PNR,
I am working on an application that needs to handle expiring airline miles. The
I'm working a program where there's an Airline class. The Airline class contains a
I'm trying to make an error check. When a user enters, int his case,
Working on rewriting the front-end of my site in Coffeescript. I understand how to
I'm working on a homework project and I'm supposed to perform a database query
Working on a project that parses a log of events, and then updates a
Working on a small game using an HTML5 canvas, and javascript. And it's working
Working with an undisclosed API, I found a function that can set the number

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.