Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Scatter/Gather with DataRow & DataSet
Message
 
 
To
16/09/2008 15:20:01
General information
Forum:
ASP.NET
Category:
ADO.NET
Environment versions
Environment:
C# 3.0
OS:
Windows XP
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01348001
Message ID:
01348013
Views:
17
>I don't know if it is possible unless you keep a historical database out there to store your deletes in. You didn't mention how long you want to be able to maintain the deleted record before purging it for good...
>

In the database we're using Deleted field to mark records for deleting. So, delete/undelete funcitonality works fine using direct commands with SQL tables (we have a helper method in util class to run any commands). So far so good. My problem is in presentation.

The GridView is bound to a dataset, but dataset is for "display only" (since the changes are made using either util helper methods or through the Form View). My problem is to keep this DataSet in synch with the changes. I almost succeded. I'm able to delete record from DS when I delete it pressing delete button in my GridView (though this code didn't work for some time today for unknown reason - but now without any changes it works again - a mystery).

I also was able to "update" the GridView's DS when I change a record using FormView.

My problem now is that I have ability to "undelete" deleted person. This is the code I have in Undelete button click method:
protected void UndoDel_Click(object sender, EventArgs e)
    {
        LinkButton UndoDel = (LinkButton)sender;

        string SQL = "UPDATE People SET Deleted = 0 WHERE PersonID = " + UndoDel.CommandArgument;

        Util.DoCmd(SQL);   
        clseditmode.personid = null;
        this.HideForms(sender, (EventArgs)e);
        UndoDel.Visible = false;
        // Here we want to put saved DataRow into the dataset
        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();
        }

    }
What it does it restores the person in the database and inserts an empty record into my DS at the right place. But I don't want an empty record! I want to see the record with data that I attempted to save using this code
 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;

            }
So, somehow this is not correct way dealing with records in DataSet. I need a bit help here to understand if I'm going in the right direction with this or not.

Thanks again.
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