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 have often pondered this one... its probably an idiot question but here goes.
a little question. I have this code, which is works perfect for files, but
So I have this neat little javascript function that I'm using to print text
I have this little function function makewindows(){ child1 = window.open (about:blank); child1.document.write(<?php echo htmlspecialchars(json_encode($row2['ARTICLE_DESC']),
I have this little script to toggle a contact form when a button is
I've searched for this a little but I have not gotten a particularly straight
This is a little out there but I have a customer object coming back
I need a little help on this subject. I have a Web application written
I have this code in jQuery, that I want to reimplement with the prototype
This is my little big question about containers, in particular, arrays. I am writing

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.