Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
'Refreshing' SQLDataSource with new data
Message
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:
01346714
Message ID:
01346873
Views:
6
>Your code is pulling the DataSet out of the Session. When you called Delete() on the row, that sets a flag on the row that it's to be deleted. If that's all you're doing you won't see the row get removed. You have to call AcceptChanges() before it's removed from the datatable (not from the database). There isn't any update happening to update the backend. Something like a DataAdapter would be necessary for persistence to the database; in your code, you're handling deleting it out of the database so that's not even necessary.
>
>>you mean run even this simple UpdateCommand with parameter, correct? In fact, I have a little SP for this as well, so we may call it instead with parameter.
>
>Yes.

With AcceptChanges() it now works.

I have another question - how can I get some record field values? I tried to incorporate the original RowDeleted code into the new code, but I'm not sure how to get First and Last Name.

Here is the current code (undo does undo but not refresh the grid correctly yet - this should be simple enough to fix).
protected void ProfilesGrid_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int id = (int)this.ProfilesGrid.DataKeys[e.RowIndex].Values["PersonID"];
        
        //   int perid=  (int) Convert.ToInt16(this.ProfilesGrid.SelectedDataKey.Value);
        //{
        string SQL = "UPDATE People SET Deleted = 1 WHERE PersonID = " + id.ToString(); 
        //        e.CommandArgument;
        Util.DoCmd(SQL);

        int pi = ProfilesGrid.PageIndex * 19;
        if (Session["dts"] != null)
        {
            DataSet dts = (DataSet)Session["dts"];
            
            dts.Tables[0].Rows[e.RowIndex+pi].Delete();
            dts.Tables[0].AcceptChanges();  
            ProfilesGrid.DataSource = dts;
            ProfilesGrid.DataBind();
            Session["dts"] = dts;
        }

        LinkButton UndoDel = (LinkButton)this.plchStatusControls.FindControl("UndoDel");

        UndoDel.Text = "Undo";
        UndoDel.Visible = true;
        UndoDel.CommandName = "Undelete";
        UndoDel.CausesValidation = false;
        clseditmode.personid = id.ToString();

        UndoDel.CommandArgument = id.ToString();
       // DataRowView view = e.RowIndex  .DataItem as DataRowView;
       // string PersonName = view["FirstName"].ToString() + " " + view["LastName"].ToString();
        this.DisplayMessage("Removed  click to ");
        
    }
And this was the original code
protected void ProfilesGrid_RowDeleted(object sender, GridViewDeletedEventArgs e)
    {
        if (e.Exception == null)
        {
            //LinkButton UndoDel = new LinkButton();
            // 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 = e.Keys["PersonID"].ToString();

            UndoDel.CommandArgument = e.Keys["PersonID"].ToString();           
            this.DisplayMessage("Removed " + e.Values["FirstName"] + " " + e.Values["LastName"] + " click to ");
        }
    }
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform