当IDENTITY

编程入门 行业动态 更新时间:2024-10-21 15:30:30
本文介绍了当IDENTITY_INSERT时,无法在表'PhotoAlbumTable'中为标识列插入显式值...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我一直想弄清楚如何解决这个问题4个小时了。 我将我的表的主键设置为是自动的身份是分配一个唯一的号码,但我仍然遇到这个问题,这是我的代码的一部分:

I've been trying to figure out how to fix this for 4 hours now,. I have my table's primary keys set to is identity YES for automatic assignment of a unique number, yet I'm still having this problem here's a part of my code:

<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="ID" DataSourceID="EntityDataSource1" DefaultMode="Insert" Height="50px" Width="125px"> <Fields> <asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" SortExpression="ID" InsertVisible="false"/> <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" /> <asp:CommandField ShowInsertButton="True" /> </Fields> </asp:DetailsView> <asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=AnimeCoffeeEntities" DefaultContainerName="AnimeCoffeeEntities" EnableFlattening="False" EntitySetName="PhotoAlbumTables" OnInserted="EntityDataSource1_Inserted" EnableInsert="True"> </asp:EntityDataSource>

这里是我的代码:

and here's my code behind:

protected void EntityDataSource1_Inserted(object sender, EntityDataSourceChangedEventArgs e) { if (e.Entity != null) { PhotoAlbumTable myPhotoAlbum = (PhotoAlbumTable)e.Entity; Response.Redirect(string.Format("~/Demos/ManagePhotoAlbum.aspx?PhotoAlbumID={0}", myPhotoAlbum.ID.ToString())); } }

推荐答案

您正在为标识列插入值。但是您已在该列上启用了标识插入。 而是打开这样的表格上的身份插入,这样你就可以指定自己的身份值。 You're inserting values for the identity column. But you have turned on identity insert on that column. Instead turn on identity insert on the table like this so that you can specify your own identity values. SET IDENTITY_INSERT PhotoAlbumTable ON INSERT INTO PhotoAlbumTables /*Note the column list is REQUIRED here, not optional*/ (ID, Name) VALUES (20, 'John') SET IDENTITY_INSERT PhotoAlbumTable OFF

[请接受/上调 - 投票答案或解决方案,为您鼓励parti cipation]

[Please accept/up-vote answers or solutions that work for you to encourage participation]

嘿伙计们我现在知道了, 之所以发生这种情况,是因为我将我的主键设置为是我之后的身份制作了一个实体框架图以将其挂钩到我的控件中,因此实体框架图不会更新谁是是身份列。神奇地更新图表之后一切正常。 Hey Guys I got it now, It happened because I made my Primary keys set to is Identity AFTER I made an Entity FrameWork Diagram to hook it in my controls, so the Entity FrameWork Diagram is not updated with who are the "is Identity" columns. After updating the diagram magically everything worked fine.

更多推荐

当IDENTITY

本文发布于:2023-11-16 01:36:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1599816.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:IDENTITY

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!