Quantcast
Channel: VBForums - Database Development
Viewing all articles
Browse latest Browse all 2918

[RESOLVED] IDENTITY_INSERT problem using Sql Server

$
0
0
I am getting yelled at by sql server when I try to create a new row in my Jobs table through my C# code.

The Jobs table has a PK, Control. It is an integer. It is not an identity column. I am looking at it right now in SSMS and it says Identitfy Specification = No. (If I had designed this table, trust me it would've been identity = yes but I am trying to work with what I've got).

The code that is giving me a problem is the Update using a table adapter:
Code:

            // Add the row we created to the table
            dtDest.AddJobsRow(drDest);
            int result = taJobs.Update(dtDest);

I exception and it says 'Cannot insert explicit value for indentity column in table 'Jobs' when IDENTITY_INSERT is set to OFF'.
So two questions, where is it set to off? And why would that even be relevant if it's not an identify field?

Oh, let me add, because I think this is relevant, that there is stored procedure that inserts Jobs records and it goes:
Code:

        INSERT Jobs
                (Control, SONumber, ...
        VALUES
                (@NewControl, @SONumber, ...

Because you should be allowed to insert a value for Control, and here you can, but why can't I in the code above?

Many thanks!

Viewing all articles
Browse latest Browse all 2918

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>