I am frequently getting this SQL error when trying to run my code. What is wrong with my database?
Database code in Visual Studio 2012:
CREATE TABLE [dbo].[testtbl]
(
[Id] INT NOT NULL IDENTITY,
[name] NCHAR (10) NULL
);
The error is:
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
An explicit value for the identity column in table 'testtbl' can only be specified when a column list is used and IDENTITY_INSERT is ON.
Thanks for any advice.
Clearly you are trying to insert a value into [Id]
. That field is IDENTITY
which means the database generates it for you. Adjust your insert statement to exclude the [Id]
column.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.