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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:47:05+00:00 2026-05-14T06:47:05+00:00

I have this little question that’s been on my mind for a while now.

  • 0

I have this little question that’s been on my mind for a while now.

Here it goes:

Is it possible to temporary disable the Auto_Increment on the column ID.

So that I can add a new row to the table and being able specify the ID value when inserting the row.

And then in the end enable the Auto_Increment again, and let do its work as usual?

And if its possible how can I do it?

The table structure is very simple

Column name (attributes)

ID (Primary Key, Auto Increment, int, not null)
Name (nvarchar(100), not null)

Note:

  • The table name is: People.
  • Let’s also consider that the table already has data and cannot be changed.
  • The database server is SQL Server CE.
  • The SQL commands will be executed in a C# program, if it’s of any help.

I really hope its possible, it would come very handy.

Thanks

EDIT

SqlActions SqlActions = new SqlActions();

SqlCeCommand SqlCmd = new SqlCeCommand("SET IDENTITY_INSERT People ON", SqlActions.Connection());

try
{
    SqlCmd.ExecuteNonQuery();
}
catch (SqlCeException Error)
{
    Console.WriteLine(Error.ToString());
}

string query = "INSERT INTO People SET (ID, Nome) VALUES (@ID, @Nome)";

SqlCeCommand SqlInsert = new SqlCeCommand(query, SqlActions.Connection());

SqlInsert.Parameters.AddWithValue("@ID", 15);
SqlInsert.Parameters.AddWithValue("@Nome", "Maria");

try
{
    SqlInsert.ExecuteNonQuery();
}
catch (SqlCeException Error)
{
    Console.WriteLine(Error.ToString());
}

The connection string is working, I have tried it.

He reports:

There was an error parsing the query.
[ Token line number = 1,Token line
offset
= 20,Token in error = SET ]

SOLUTION thanks to OrbMan

        SqlActions SqlActions = new SqlActions();

        SqlCeCommand SqlCmd = new SqlCeCommand("SET IDENTITY_INSERT People ON", SqlActions.Connection());
        try
        {
            SqlCmd.ExecuteNonQuery();

            string query = "INSERT INTO People (ID, Nome) VALUES (@ID, @Nome)";
            SqlCmd.CommandText = query;
            SqlCmd.Parameters.AddWithValue("@ID", 15);
            SqlCmd.Parameters.AddWithValue("@Nome", "Vania");
            SqlCmd.ExecuteNonQuery();
        }
        catch (SqlCeException Error)
        {
            Console.WriteLine(Error.ToString());
        }
  • 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-14T06:47:05+00:00Added an answer on May 14, 2026 at 6:47 am

    I believe you can use SET IDENTITY_INSERT. I am not sure if this works in all versions.

    Update 2:

    Try this version:

    SqlActions SqlActions = new SqlActions();
    SqlCeCommand SqlCmd = new SqlCeCommand("SET IDENTITY_INSERT People ON", SqlActions.Connection());
    try
    {
        SqlCmd.ExecuteNonQuery();
        string query = "INSERT INTO People (ID, Nome) VALUES (@ID, @Nome)";
        SqlCmd.CommandText = query;
        SqlCmd.Parameters.AddWithValue("@ID", 15);
        SqlCmd.Parameters.AddWithValue("@Nome", "Maria");
        SqlCmd.ExecuteNonQuery();
    }
    catch (SqlCeException Error)
    {
        Console.WriteLine(Error.ToString());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I little while back I posted this question . I have updated that question
I guess this question that would have already been asked here. I searched but
This is a little different than the questions that have already been asked on
This is a little weird question, I have a GUI class that in the
This is a running question that I have updated to hopefully be a little
I have little question. I found this on internet: Type t = typeof(MyClass); MethodInfo[]
I have little question about how web browser retrieve webpage? I know this User
This is a very simple question yet I have little knowledge in Linux and
This question is related to database/RDBMS where i have little knowledge regarding performance and
This question may seem a little bit stackoverflow-implementation specific, but I have seen a

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.