为什么我的记录在 SQL 服务器中使用 ASP.NET 没有被删除?

Why my record is not deleted in SQL Server using ASP.NET?

我正在尝试在删除目录后从数据库中删除记录。

我有一个删除按钮,一旦我点击按钮,它必须调用ajax,然后删除Folder如果它存在,一旦它删除文件夹,然后删除一条记录在数据库上

这是我的 Ajax 代码:

// Delete Folder
$("#btnDeleteFolder").click(function () {
    var dirPath = $('#ContentPlaceHolder1_txtPath_I').val();
    var folderName = $('#txtFolderName').val();
    var location = $('#ddlLocation option:selected').text();
    alert("FolderName = "+folderName);
    alert("Location = "+location);

    //alert('calling path =' + dirPath);
    $.ajax({
        method: 'post',
        url: "GetAllFolderDetails.asmx/setDeleteFolder",

        data: {
            dirLocation: dirPath,
            folderName: folderName,
            location: location
        },

        dataType: "json",
        success: function (data) {
            location.reload(true);
            //alert("Success");

        },
        error: function (result) {
            alert("Error");
        }
    });
});

Asmx.cs代码:

public void setDeleteFolder(string dirLocation,string folderName,string location)
{
    // First check Whether Other Folder or Files Exists inside the folder
    // If it Exist, Delete those files and then delete your SELECTED Folder
    string insidePath = Server.MapPath("~/" + dirLocation);
    string[] files = Directory.GetFiles(insidePath, "*", SearchOption.AllDirectories);

    foreach (string file in files)
    {
        File.Delete(file);
    }

    if (Directory.Exists(insidePath))
    {
        Directory.Delete(insidePath);

        // Once the File Directory has deleted successfully, Then Delete the record from Database
        var locationID = 0;

        switch (location)
        {
            case "Store1":
                locationID = 1;
                break;

            case "Store1":
                locationID = 2;
                break;

            case "Store1":
                locationID = 3;
                break;
        }

        string cs = ConfigurationManager.ConnectionStrings["webConfigConnectionString"].ConnectionString;

        using (SqlConnection con = new SqlConnection(cs))
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;

            cmd.CommandText = "DELETE Folder WHERE StoreID = @Storeid AND FolderName = @FolderName)";

            cmd.Parameters.AddWithValue("@Storeid", 1);  // For testing I directly give the value for parameters
            cmd.Parameters.AddWithValue("@FolderName", "Sales");

            con.Open();
            cmd.ExecuteNonQuery();
        }
    }

    JavaScriptSerializer js = new JavaScriptSerializer();
    Context.Response.Write(js.Serialize("Successfully deleted"));
}

错误信息:

Internal Server Error

备注

我的目标文件夹是已成功删除。但是在数据库中,记录没有被删除

换行

cmd.CommandText = "DELETE Folder WHERE StoreID = @Storeid AND FolderName = @FolderName)";

cmd.CommandText = "DELETE from Folder WHERE StoreID = @Storeid AND FolderName = @FolderName";