与IDENTITY_INSERT设置为OFF问题? : - / [英] Problems with IDENTITY_INSERT Set to OFF? :-/
问题描述
我试图插入订单的详细信息到我的数据库,并口口声声说:
I'm trying to insert order details into my DB, and it keeps saying:
无法插入为标识列显式值表'订单',当IDENTITY_INSERT设置为OFF。
Cannot insert explicit value for identity column in table 'Orders' when IDENTITY_INSERT is set to OFF.
所有我想要做的就是简单地插入用户的用户ID为用户标识柱通过使用 WebSecurity.CurrentUserId
- 这是为什么不工作
All I am trying to do is simply insert the users UserId into the UserId column, by using WebSecurity.CurrentUserId
- Why is this not working?
我有:
dbase.Execute("INSERT INTO Orders
(UserId, OrderId, Status)
VALUES
(@0, @1, @2)",
WebSecurity.CurrentUserId,
Session["OSFOID"],
"Confirmed");`
所以,你可以看到,这是很简单的。 ?但是,为什么不将它的工作。
So, as you can see, it's pretty simple. But, why won't it work?
我的表的定义是:
推荐答案
除非你启用的做身份插入的能力(通过设置标识插入的 的作为该表),你不准触摸列 - 。数据库拥有它
Unless you enable the ability to do identity-insert (by setting identity-insert on for that table), you are NOT ALLOWED to touch that column - the database owns it.
无论是启用标识插入 简单的或:不要尝试插入的用户ID(让数据库创建一个新的ID)。
Either enable identity insert briefly, or: don't try to insert the UserId (let the DB create a new id).
按联机丛书,的 SET IDENTITY_INSERT
:
As per books online, SET IDENTITY_INSERT
:
SET IDENTITY_INSERT Orders ON
INSERT INTO Orders (UserId, OrderId, Status) VALUES (@0, @1, @2)
SET IDENTITY_INSERT Orders OFF
更可能的是:如果这是订单
表,如果身份不会对的OrderId
?你还是有同样的问题,因为你正在试图控制的OrderId
,当然。
More likely, though: if this is the Orders
table, should the identity not be on OrderId
? You'd still have the same problem since you are trying to control the OrderId
, of course.
这篇关于与IDENTITY_INSERT设置为OFF问题? : - /的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!