开发者

Can't submit changes to database or page controls

I've got a pretty simple page, consisting of two DropDownLists populated from the database, and a button. The purpose of the page is pretty simply to allow users to delete an entry from the database. When the button is clicked then a simple LINQ query is executed to delete the intended target, and remove the entry from the dropdownlists, but it doesn't work unless the response is 开发者_JAVA百科redirected within that function, even if SubmitChanges() was called. Why would this happen?

Edit: Code

protected void Page_Init(object sender, EventArgs e)
{
    var result = Database.DB.Data.GetTable<Database.tbl_module_>().Where(module => module.deptCode == ((User)Session["user"]).deptCode);
    foreach (var row in result)
    {
        this.listModuleCode.Items.Add(new System.Web.UI.WebControls.ListItem(row.code));
        this.listModuleTitle.Items.Add(new System.Web.UI.WebControls.ListItem(row.title));
    }
}
protected void Delete_Click(object sender, EventArgs e)
{
    var DB = Database.DB.Data;
    var table = DB.GetTable<Database.tbl_module_>();
    var result = table.Where(module => module.deptCode == ((User)Session["user"]).deptCode && module.code == listModuleCode.SelectedItem.Text);
    listModuleCode.Items.Remove(listModuleCode.SelectedItem);
    listModuleTitle.Items.Remove(listModuleTitle.SelectedItem);
    table.DeleteAllOnSubmit(result);
    DB.SubmitChanges();
    Response.Redirect("deletemodule.aspx"); // redirect to this page
}


We need to see your code to help more probably. However:

You need to make sure it knows to delete on submit:

var q = db.Customers.Where(c => c.CustomerID == 2).Single();
db.Customers.DeleteOnSubmit(q);
db.SubmitChanges();

Don't forget you can pass straight SQL to the object:

db.ExecuteCommand("DELETE FROM Customers WHERE ID = 2");

Which you might think is easier.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜