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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:04:43+00:00 2026-06-09T00:04:43+00:00

How to change identity specification for a column using sql query ? Only using

  • 0

How to change identity specification for a column using sql query ? Only using c# coding. Pls Help.
Here i want to add one more column as PaperId while creating new table in following code.
I need to assign columns property as identity specification yes and identity increment 1.

if (rbtnEng.Checked == true)
{
    con.Open();
    char[] arr = new char[] { 'n', 'g', 'l', 'i', 's', 'h' };
    string str = "CREATE TABLE " + Label1.Text.Trim() + txtpaperset.Text.Trim() 
    + rbtnEng.Text.TrimEnd(arr) + "(" + "quesNo int NOT NULL PRIMARY KEY, " 
    + "question varchar(1000) NOT NULL," + "ansA varchar(500) NOT NULL, " 
    + "ansB varchar(500) NOT NULL, " + "ansC varchar(500) NOT NULL, " 
    + "ansD varchar(500) NOT NULL, " + "rightAns varchar(50) NOT NULL " + ")";
    SqlCommand cmd = new SqlCommand(str, con);
    cmd.ExecuteNonQuery();
    Label2.Text = Label1.Text + txtpaperset.Text + rbtnEng.Text.TrimEnd(arr);
    lblerrormsg.Text = "PaperSet Created Sucessfully!";
    txtpaperset.ReadOnly = true;
    btnpaper.Enabled = false;
    rbtnEng.Enabled = false;
    rbtnMar.Enabled = false;
    UpdatePanel2.Visible = true;
    txtQuestNo.Text = Convert.ToString(1);
    con.Close();
}

else if....
  • 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-09T00:04:45+00:00Added an answer on June 9, 2026 at 12:04 am

    First, this is bad. Don’t add so many strings like this; use string.Format().

    string str = string.Format("CREATE TABLE {0}{1}{2} (" 
    + "quesNo int NOT NULL PRIMARY KEY, question varchar(1000) NOT NULL, " 
    + "ansA varchar(500) NOT NULL, ansB varchar(500) NOT NULL, " 
    + "ansC varchar(500) NOT NULL, ansD varchar(500) NOT NULL, " + 
    + "rightAns varchar(50) NOT NULL )",
    Label1.Text.Trim(),
    txtpaperset.Text.Trim(),
    rbtnEng.Text.TrimEnd(arr));
    

    But that’s just my opinion.

    Here’s how to create an identity column.

    PaperId int identity(1,1)
    

    Just add it to your str string.

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

Sidebar

Related Questions

I have a table which has no identity column. I want to change a
I want to change from one XML (XHTML) file to another using XSLT. In
I want to update column which has datatype of nvarchar. Want to change the
I need to change the primary key of a table to an identity column,
I have a simple country table using a identity column for the primary key.
Can we change step value of already existing identity column ? If yes what
To change the language on my website I've been using ressources and this code:
I added a new identity column, and I need to update it so that
I have an ios application that runs on xcode 3.2.6. I want to change
I have many tables; each has a primary key which is an Identity column

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.