簡體   English   中英

使用請求querystring asp.net

[英]using request querystring asp.net

我想刪除一個子類別並顯示有關刪除的消息,但是我的查詢沒有刪除任何內容。 請幫我。

類別表在這里

<a href="SubCategories.aspx?Process=Delete&CategoryID=<%#Eval("CategoryID") %>" title="Delete" class="tip" ><span class="icon12 icomoon-icon-remove"></span></a>

if (Process == "Delete")
{
    DataTable dtProducts = system.GetDataTable("Select COALESCE(COUNT(1),0) as TOTAL from TBLPRODUCTS where CategoryID = " + CategoryID);
    if (dtProducts.Rows[0]["TOTAL"].ToString() == "0")
    {
        SqlConnection cnn = new SqlConnection();
        SqlCommand cmd = new SqlCommand("Delete from TBLCATEGORIES where SubCategoryID=" +  Request.QueryString["CategoryID"] );

        try {
            cnn.Open();
             cmd.ExecuteNonQuery();}

        catch {
            lblMsg.Text = "Error!";
        }

        finally {  
             cnn.Close(); 
        }
             DeleteMsg.Visible = true;
    }
}

試試這個...

if (Process == "Delete")
    {
        DataTable dtProducts = system.GetDataTable("Select COALESCE(COUNT(1),0) as TOTAL from TBLPRODUCTS where CategoryID = " + CategoryID);
        if (dtProducts.Rows[0]["TOTAL"].ToString() == "0")
        {
            SqlConnection cnn = new SqlConnection("data source=localhost\<instance name>;initial catalog=Shqipar; Integrated Security=SSPI;");
            SqlCommand cmd = new SqlCommand("Delete from TBLCATEGORIES where SubCategoryID=" +  Request.QueryString["CategoryID"] );

            try {
                cnn.Open();
                 cmd.connection=cnn;
                 cmd.ExecuteNonQuery();}

            catch(Exception ex) {
                lblMsg.Text = ex.message;
            }

            finally {  
                 cnn.Close(); 
            }
                 DeleteMsg.Visible = true;
        }
    }
else
{
 InfoMsg.Visible=True;
}

我只是將SQLConnection分配給SQLCommand ...

希望這會有所幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM