Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old August 11th, 2012, 11:31 AM
Friend of Wrox
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile Store update, insert, or delete statement affected an unexpected number of rows (0).

Hello all, I got suddenly a new error, I found for it at google but solutions seems entire different approach.

My code is below.

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="false"
        AllowSorting="True" DataSourceID="EntityDataSource1">
            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ItemStyle-Width="100px" />
            <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" ItemStyle-Width="200px" />
            <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" ItemStyle-Width="300px" />
            <asp:TemplateField HeaderText="User Name">
                    <asp:Label ID="lblUsers" runat="server" Text='<%# GetUserName(Eval("UserId")) %>'></asp:Label>
                <asp:DropDownList ID="ddlUsers" runat="server" DataSourceID="SqlDataSource1" DataTextField="UserName" DataValueField="UserId"
                        SelectedValue='<%# Bind("UserId") %>'>

    <asp:EntityDataSource ID="EntityDataSource1" runat="server"
        DefaultContainerName="ASPNETDBEntities" EnableDelete="True"
        EnableFlattening="False" EnableInsert="True" EnableUpdate="True"

    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
        SelectCommand="SELECT UserId,UserName FROM [aspnet_Users]"></asp:SqlDataSource>
and code behind is

protected string GetUserName(object userid)
        string userName = (string)Membership.GetUser(userid).UserName;

        return userName;
But I am getting error "Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries."

I am getting this error on Edit and Delete operation only, if I add a DetailsView to insert record then it works fine. Also if I don;t use AutoGenerateColumns=False, then also it works.

Please tell me what is issue and how I resolve it???
Old August 13th, 2012, 02:32 AM
Friend of Wrox
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts

Guys, problem has been solved. Imar has provided solution here

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bulk Insert TSQL in DTS – Rows Affected Count sjm SQL Server DTS 2 May 30th, 2008 11:40 AM
insert and/or update statement carswelljr SQL Language 3 September 28th, 2006 10:03 AM
INSERT, UPDATE, DELETE dagad ASP.NET 2.0 Professional 0 September 27th, 2006 01:22 AM
Views-Insert/update/delete lily611 SQL Language 2 November 29th, 2004 03:41 AM
Update, insert and delete Trigger khautinh SQL Server 2000 2 September 17th, 2003 11:45 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.