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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:38:02+00:00 2026-05-22T21:38:02+00:00

I am developing a career website for one of my projects. I am using

  • 0

I am developing a career website for one of my projects. I am using Visual Studio 2010 and ASP.NET Web Forms to code.

My problem is I have got a table named Companies which consists of columns Company ID, Company Name, Company Address and Company Phone. CompanyID is my primary key. I am trying to insert new companies to this table using Linq-to-SQL.

When I execute the following piece of code, if the database is empty, the code works properly but if it is not it can’t auto increment the CompanyID and gives me a database error.

How can I solve this issue?

Thanks in advance.

protected void Button1_Click(object sender, EventArgs e)
{
    Label_error.Text = "";
    Page.Validate();

    if (Page.IsValid)
    {
        CareerDataContext db = new CareerDataContext();

        Company newCompany = new Company { coName = TextBox_coName.Text, coAddress = TextBox_coAddress.Text, coPhone = int.Parse(TextBox_coPhone.Text) };
        Company fCompany = db.Companies.SingleOrDefault(company => company.coName.Equals(TextBox_coName.Text));

        if (fCompany == null)
        {
            db.Companies.InsertOnSubmit(newCompany);
            db.SubmitChanges();
        }
        else
            Label_error.Text = "This username is already in use";
    }
}
  • 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-22T21:38:03+00:00Added an answer on May 22, 2026 at 9:38 pm

    If your CompanyID is a uniqueidentifier then you can pass in Guid.NewGuid();

    For example:

    Company newCompany = new Company { coID = Guid.NewGuid(), coName = TextBox_coName.Text, coAddress = TextBox_coAddress.Text, coPhone = int.Parse(TextBox_coPhone.Text) };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Developing a chrome extension using javascript is one of my university projects. I don't
Developing locally in Visual Studio 2010 my page looks great. When I deploy to
When developing a .Net web application, if a run time error is generated, it
Developing a multilingual application in VB.Net 2008, Im able to add resources to forms
I started my career on Linux/Unix, and moved over to Windows and Visual Studio.
When developing a Web service(Hospital Management System) using Java EE, is it necessary that
Developing a C# .NET 2.0 WinForm Application. Need the application to close and restart
Currently developing an application using the newest version of symfony, obtained through PEAR. This
While developing a firefox extension, I create a wizard window from overlay.js using: this.wizard
Developing a desktop application based on Java + Swing I faced the problem 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.