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

  • Home
  • SEARCH
  • 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
Developing a multilingual application in VB.Net 2008, Im able to add resources to forms
Developing an ASP.NET MVC 3 application (my first) and running into some trouble with
I started my career on Linux/Unix, and moved over to Windows and Visual Studio.
Developing a C# .NET 2.0 WinForm Application. Need the application to close and restart
Iam developing one application.In that iam placing the radio buttons(uiimageview) on table view and
While developing an application using gwt in ecliplse crashed. Now the server is running
For developing an devices monitor system, I am using a InetAdress isReachable method to
Im developing an app for iPhone, in wich one of the functionalities is an

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.