0
votes

When I try to Update or Delete a single selected item, it throws a "Row not found or changed." exception. Basically I only did a linq query and use most of the auto-generate function. I added LinqDataSource1_ContextCreated function, but it does not help.

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
               AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" 
               DataSourceID="LinqDataSource1" Width="100%" 
               onrowdatabound="GridView1_RowDataBound">
        <Columns>
            <asp:BoundField DataField="JobId" HeaderText="JobId" ReadOnly="True" />
            <asp:BoundField DataField="JobTitle" HeaderText="JobTitle" />
            <asp:BoundField DataField="Summary" HeaderText="Summary"/>
            <asp:BoundField DataField="Detail" HeaderText="Detail" />
            <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" />
            <asp:BoundField DataField="CompanyEmail" HeaderText="CompanyEmail" />
            <asp:CheckBoxField DataField="IsTop" HeaderText="IsTop"   />
            <asp:CheckBoxField DataField="IsShown" HeaderText="IsShown" />
              <asp:BoundField DataField="PostDate" HeaderText="PostDate" 
                ApplyFormatInEditMode="True" DataFormatString="{0:MMM,dd,yy}" 
                HtmlEncode="False" ReadOnly="True"/>
        <asp:BoundField DataField="UserName" HeaderText="UserName" ReadOnly="True"/>

    </Columns>
</asp:GridView>
<asp:LinqDataSource ID="LinqDataSource1" runat="server" 
           ContextTypeName="JobPostDataContext" EntityTypeName="" 
           onselecting="LinqDataSource1_Selecting" TableName="JobLists" 
           EnableDelete="True" EnableUpdate="True" >
            </asp:LinqDataSource>

  protected void LinqDataSource1_Selecting(object sender, LinqDataSourceSelectEventArgs e)
    {
        JobPostDataContext db = new JobPostDataContext();

        var query = from uM in db.aspnet_Memberships
                    join uD in db.UserDetails
                    on uM.UserId equals uD.UserId
                    join u in db.aspnet_Users
                    on uM.UserId equals u.UserId
                    join jL in db.JobLists
                    on uM.UserId equals jL.UserId
                    where u.UserName == Request.QueryString["UserName"]

                    select new
                    {
                        jL.JobId,
                        jL.JobTitle,
                        jL.Summary,
                        jL.Detail,
                        jL.CompanyName,
                        jL.CompanyEmail,
                        jL.PostDate,
                        jL.IsTop,
                        jL.IsShown,
                        u.UserName
                    };

         e.Result = query;
    }

    protected void LinqDataSource1_ContextCreated(object sender, LinqDataSourceStatusEventArgs e)
    {

        JobPostDataContext db = e.Result as JobPostDataContext;

        System.Data.Linq.DataLoadOptions dl = new System.Data.Linq.DataLoadOptions();

        dl.LoadWith<JobList>(d => d.JobId);

        db.LoadOptions = dl;

    }  

Row not found or changed. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.Linq.ChangeConflictException: Row not found or changed.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[ChangeConflictException: Row not found or changed.]
System.Data.Linq.ChangeProcessor.SubmitChanges(ConflictMode failureMode) +996823
System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode) +378
System.Data.Linq.DataContext.SubmitChanges() +23 System.Web.UI.WebControls.LinqToSqlWrapper.SubmitChanges(DataContext dataContext) +9
System.Web.UI.WebControls.LinqDataSourceView.UpdateDataObject(Object dataContext, Object table, Object oldDataObject, Object newDataObject) +115 System.Web.UI.WebControls.LinqDataSourceView.UpdateObject(Object oldEntity, Object newEntity) +262
System.Web.UI.WebControls.QueryableDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) +115
System.Web.UI.WebControls.ContextDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) +100
System.Web.UI.WebControls.LinqDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) +41
System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) +95
System.Web.UI.WebControls.GridView.HandleUpdate(GridViewRow row, Int32 rowIndex, Boolean causesValidation) +1226
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +716
System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e) +95
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e) +121
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +125
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +169
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +9
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +176
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563

1

1 Answers

0
votes

Why are you not setting

 EntityTypeName="JobLists"

And then in your select selecting jl ?

I.e.:

protected void LinqDataSource1_Selecting(object sender, LinqDataSourceSelectEventArgs e) 
{
    JobPostDataContext db = new JobPostDataContext();

    var query = from uM in db.aspnet_Memberships
                join uD in db.UserDetails
                on uM.UserId equals uD.UserId
                join u in db.aspnet_Users
                on uM.UserId equals u.UserId
                join jL in db.JobLists
                on uM.UserId equals jL.UserId
                where u.UserName == Request.QueryString["UserName"]

                select jl;


     e.Result = query;
}