Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Code suddenly stopped working
Message
 
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
C# 3.0
OS:
Windows XP
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01347992
Message ID:
01347997
Views:
17
Ok, for a more strange reason the code started to work again.

However, I have a problem.

I want to be able to save record before deleting in a dataset and if I undelete the record I want to insert it back.

So, I'm trying to do this with this code
 this.DeletedPersonRow = dts.Tables[0].Rows[pi]; //Save Person we're about to delete
                Session["DeletedPersonRow"] = this.DeletedPersonRow;                
                this.DeletedRowIndex = pi;
                ViewState["DeletedRowIndex"] = this.DeletedRowIndex; 
in the delete method

and restore with this code in undelete
if (Session["DeletedPersonRow"] != null && Session["dts"] != null)
        {
            DataSet dts = (DataSet)Session["dts"];
            DataRow dr = (DataRow) Session["DeletedPersonRow"];
            dts.Tables[0].Rows.InsertAt(dr, (int)ViewState["DeletedRowIndex"]);
            dts.AcceptChanges();
            Session.Remove("DeletedPersonRow") ;            
            ViewState.Remove("DeletedRowIndex") ; 
            
            Session["dts"] = dts;
            this.ProfilesGrid.DataBind();
        }
However, I see just a blank record inserted instead of the record with data. Do you see what is faulty in my approach?

Thanks a lot in advance.


>Hi everybody,
>
>Here is the code I tested about a day ago and it worked fine. Today it's either not working, or working but incorrectly and I could not figure out what's wrong. The record is getting deleted from the table in SQL Server, but the GridView still shows it. Only if I refresh the GridView (there is a button on the form to bring all records), I see that the records are really gone. Also no message is displayed on the page to undelete the person.
>
>Do you see what may be wrong?
>
>Or is it a time to re-start computer?
>
>Thanks in advance.
>
>
>int pi = (ProfilesGrid.PageIndex * 20) + e.RowIndex;
>
>            TextBox tb;
>            if (this.ProfilesGrid.Rows.Count <= pi)
>            {
>              tb = (TextBox)  this.ProfilesGrid.Rows[e.RowIndex].Cells[13].Controls[0]; }
>                else{
>                   tb = (TextBox) this.ProfilesGrid.Rows[pi].Cells[13].Controls[0];
>            }
>            int id = (int)Convert.ToInt16(tb.Text.ToString()); //this.ProfilesGrid.Rows[pi].Cells[14] )
>
>            string SQL = "UPDATE People SET Deleted = 1 WHERE PersonID = " + id;
>            //        e.CommandArgument;
>            Util.DoCmd(SQL);
>
>            // pi -= 1;
>
>            if (Session["dts"] != null)
>            {
>                DataSet dts = (DataSet)Session["dts"];
>                this.DeletedPersonRow = dts.Tables[0].Rows[pi]; //Save Person we're about to delete
>                Session["DeletedPersonRow"] = this.DeletedPersonRow;                
>                this.DeletedRowIndex = pi;
>                ViewState["DeletedRowIndex"] = this.DeletedRowIndex; 
>                dts.Tables[0].Rows[pi].Delete();
>                dts.AcceptChanges();
>                ProfilesGrid.DataSource = dts;
>                ProfilesGrid.DataBind();                
>                Session["dts"]= dts;
>
>            }
>            // NN 05-08-08 - added LinkButton on the page itself rather than adding in run-time
>            LinkButton UndoDel = (LinkButton)this.plchStatusControls.FindControl("UndoDel");
>
>            UndoDel.Text = "Undo";
>            UndoDel.Visible = true;
>            UndoDel.CommandName = "Undelete";
>            UndoDel.CausesValidation = false;
>            clseditmode.personid = id.ToString() ; // e.Keys["PersonID"].ToString();
>
>            UndoDel.CommandArgument = id.ToString();// e.Keys["PersonID"].ToString();
>            this.DisplayMessage("Removed " + PersonName + " click to ");
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform