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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:29:36+00:00 2026-05-20T15:29:36+00:00

In short, C# throws me Dynamic SQL generation for the UpdateCommand is not supported

  • 0

In short, C# throws me “Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information”, while the table in question DOES have a Primary key (Identity, since it’s MSSQL).

My code is as following:

       void loaddata()
    {
        try
        {
            DS = new DataSet();
            sqladapt = new SqlDataAdapter("SELECT servicetag,name,defect,primkey FROM " + Properties.Settings.Default.DBtableLaptops + "", sqlcon);
            sqladapt.FillSchema(DS, SchemaType.Source);
            sqladapt.Fill(DS);
            commandBuilder = new SqlCommandBuilder(sqladapt);
            DT = DS.Tables[0];
            Laptops_datagridview.DataSource = DT; //I'm using a datagridview to edit the data.
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

    }
    void savedata()
    {
        //Doesn't work yet.
        try
        {
            sqladapt.Update(DS); // <-- Throws the aforementioned error.
            sqladapt.Dispose();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }

Data loading etc works fine, Adding new rows works aswell, and it saves it. But whenever i update or delete a row, it throws the error.
Primkey is my primary key, it’s an auto-incrementing integer.

I’ve been googling all day, but to no avail, the usual problem people have is that there is no primary key defined in the first place, but that’s not the case here.

Any input would be greatly appreciated, i’ve been shotgun-debugging for like 6 hours now.

EDIT:
The create statements for the table in question is as following:

CREATE TABLE [dbo].[laptopregistratieDB_laptops](
    [Servicetag] [text] NOT NULL,
    [Name] [text] NOT NULL,
    [Defect] [bit] NOT NULL,
    [primkey] [int] IDENTITY(1,1) NOT NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  • 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-20T15:29:37+00:00Added an answer on May 20, 2026 at 3:29 pm

    You need to actually make your primkey column a primary key:

    ALTER TABLE [dbo].[laptopregistratieDB_laptops]
       ADD CONSTRAINT PK_laptopregistratieDB_laptops PRIMARY KEY (primkey)
    

    You can also specify such a constraint when creating a table:

    CREATE TABLE [dbo].[laptopregistratieDB_laptops](
        [Servicetag] [text] NOT NULL,
        [Name] [text] NOT NULL,
        [Defect] [bit] NOT NULL,
        [primkey] [int] IDENTITY(1,1) NOT NULL,
        constraint PK_laptopregistratieDB_laptops PRIMARY KEY (primkey)
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
    

    or, if you want SQL Server to randomly generate the constraint name (not recommended, but some people do do it):

    CREATE TABLE [dbo].[laptopregistratieDB_laptops](
        [Servicetag] [text] NOT NULL,
        [Name] [text] NOT NULL,
        [Defect] [bit] NOT NULL,
        [primkey] [int] IDENTITY(1,1) NOT NULL PRIMARY KEY
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
    

    SQL Server will also randomly name the constraint if you apply a primary key constraint using the table designer (Right click next to the column you want to be primary key, choose “Set Primary Key”)

    All of these options can also be used to specify multi-column primary keys, with the exception of the [primkey] [int] IDENTITY(1,1) NOT NULL PRIMARY KEY variant. (In the designer scenario, you have to highlight multiple rows before right clicking).

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

Sidebar

Related Questions

Short version: Why does Visual Studio tell me that the code has thrown a
Long story short, one of my entities has a GeometryCollection that throws an exception
Short one: Am I correct in assuming, that the Samsung Galaxy S wifi 4.0
Does anyone have any insights regarding compiling Ruby code for Windows? I've tried both
Does anyone know why the last one doesn't work? object nullObj = null; short
I want to create a dynamic 2d array by function but it seems that
I've got a short piece of code that originally created an SqlDataAdapter object over
I was in a database this morning that has just short of 10k non
Short: (Portlet-)Container swallows Exception thrown by @PostConstruct method in backing bean. Is this behavior
Short question, is the following ok: struct X { A& x; A y; X()

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.