单击 asp 按钮在 SQL Server 中删除行 - 经典 asp 和 vbscript

发布于 2024-11-09 13:30:51 字数 1380 浏览 0 评论 0原文

我在 asp 中创建了一个网页来显示 SQL 数据库中的表。然后,我向每个表行添加按钮以更新和删除每行代码 -

    do while not objRS.EOF

    %>

    <tr> 
        <td><%= objRS("Id") %> </td>
        <td><%= objRS("Name") %> </td>
        <td><%= objRS("Address") %></td>
        <td><%= objRS("Suburb") %></td>
        <td><%= objRS("Postcode") %></td>
        <td><%= objRS("Age") %></td>
        <td><%= objRS("Email") %></td>
        <td><Center><input type="submit" value="Update"></Center></td>
        <td><center><input type="Submit" onclick="delete(<%= objRS("Id") %>)" value="Delete"></center></td>
    </tr>
    <%
        objRS.MoveNext
        loop    
        objCon.close
    %>

也是要删除的代码 -

    Function delete(index)

        Dim objCon, objRS, dSQL      
        set objCon = CreateObject("ADODB.Connection")
        objCon.open "Provider=SQLOLEDB.1;Password=xxxx;Persist Security Info=True;User ID=xxxx;Initial Catalog=Customer;Data Source=PC"

        dSQL = "DELETE FROM Customer WHERE Id=" & index

        objCon.execute(dSQL)            
        objCon.close     
    End Function

我已经到处查看,但似乎无法找到如何识别每个不同的按钮并从数据库中删除相应的行

I've created a webpage in asp to display a table from SQL database. I then added Buttons to each table row to update and delete each row code -

    do while not objRS.EOF

    %>

    <tr> 
        <td><%= objRS("Id") %> </td>
        <td><%= objRS("Name") %> </td>
        <td><%= objRS("Address") %></td>
        <td><%= objRS("Suburb") %></td>
        <td><%= objRS("Postcode") %></td>
        <td><%= objRS("Age") %></td>
        <td><%= objRS("Email") %></td>
        <td><Center><input type="submit" value="Update"></Center></td>
        <td><center><input type="Submit" onclick="delete(<%= objRS("Id") %>)" value="Delete"></center></td>
    </tr>
    <%
        objRS.MoveNext
        loop    
        objCon.close
    %>

also i the code to delete -

    Function delete(index)

        Dim objCon, objRS, dSQL      
        set objCon = CreateObject("ADODB.Connection")
        objCon.open "Provider=SQLOLEDB.1;Password=xxxx;Persist Security Info=True;User ID=xxxx;Initial Catalog=Customer;Data Source=PC"

        dSQL = "DELETE FROM Customer WHERE Id=" & index

        objCon.execute(dSQL)            
        objCon.close     
    End Function

I've looked everywhere but cant seem to find how to identify each different button and delete the corresponding row from the database

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凉薄对峙 2024-11-16 13:30:51

每行都有:

<a href="Page.asp?action=delete&ID=<%= objRS("Id") %>">Delete this</a>

然后接收页面有代码:

Dim strAction

strAction = request.querystring("action")
if(strAction = "delete")

    'Verify ID
    'Perform deletion
    'Redirect

end if

这就是传统上删除它的方式。在您的示例中,您似乎需要 AJAX 功能。将其添加到页面顶部:

<script type="text/javascript">
    function delete(RecordID){
        alert(RecordID);
    }
</script>

这是单击“删除”时尝试调用的 Javascript 函数。因此,如果您想要这样做,这将是您调用删除脚本的 AJAX 请求的模板。

In each row have:

<a href="Page.asp?action=delete&ID=<%= objRS("Id") %>">Delete this</a>

Then the receiving page, have the code:

Dim strAction

strAction = request.querystring("action")
if(strAction = "delete")

    'Verify ID
    'Perform deletion
    'Redirect

end if

This is how you would traditionally delete it. In your example, you seem to want an AJAX function. Add this to the top of your page:

<script type="text/javascript">
    function delete(RecordID){
        alert(RecordID);
    }
</script>

That's the Javascript function you are trying to call when delete is clicked. So that would be your template to call an AJAX request to the delete script if that is the way you want to do it.

扮仙女 2024-11-16 13:30:51

您似乎正在尝试使用 Javascript 调用 ASP 代码。那是行不通的。

如果您的删除函数位于单独的 ASP 脚本中,那么您可以创建一个 Javascript 方法来处理按钮单击并直接使用 GET 或使用 Ajax 调用来调用其他 ASP 脚本。然后你必须重新加载原始页面。

It looks like you're trying to invoke ASP code with Javascript. That ain't gonna work.

If you had your delete function in a separate ASP script, then you can create a Javascript method to handle the button clicks and call the other ASP script, either directly with a GET or with an Ajax call. Then you'd have to reload the original page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文