简体   繁体   English

如何删除子类别并显示成功消息

[英]how to delete subcategory and display success message

I want to delete a sub category and display a message about the deletion upon success. 我想删除一个子类别,并在成功后显示一条有关删除的消息。 However, my query does not delete anything. 但是,我的查询没有删除任何内容。 How can I fix it? 我该如何解决?

table structure: 表结构:

Software 
CategoryID=100, SubCategoryID=NULL (main category)
Asp.Net
CategoryID=100, SubCategoryID=100 (sub category)`

code

if (Process == "Delete")
{
    system.cmd("DELETE FROM TBLCATEGORIES where SubCategoryID =" + CategoryID);
    DeleteMsg.Visible = true;
}

Delete Message 删除留言

      <div class="alert alert-info"  id="DeleteMsg" runat="server"  visible="false">

You have an error in your SQL query. 您的SQL查询中有一个错误。 You should write: 您应该写:

     system.cmd("DELETE FROM TBLCATEGORIES where SubCategoryID = " + CategoryID);

In addition you should use parameters in your SQL queries. 另外,您应该在SQL查询中使用参数。 It's more efficient and prevent from SQL injection attacks ( Adding parameter to command ). 它效率更高,并且可以防止SQL注入攻击( 将参数添加到command )。

Instead of writing the query directly in code; 而不是直接在代码中编写查询; first check the queries in Sql server management studio, because your query is not correct, I believe you want to delete all the sub categories below a specific category, if that is the case then you will match the category column and that is it. 首先在Sql Server Management Studio中检查查询,因为您的查询不正确,我相信您想删除特定类别下的所有子类别,如果是这种情况,那么您将匹配类别列。

Hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM