English 中文(简体)
按钮点击asp删除SQL server中的行-经典的asp和vbscript
原标题:Button Click for asp to Delete Row in SQL server - classic asp and vbscript

我在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

我到处都找了,但似乎找不到如何识别每个不同的按钮并从数据库中删除相应的行

最佳回答

每一行都有:

<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>

这是您在单击delete时试图调用的Javascript函数。因此,如果你想这样做的话,这将是你的模板,可以调用AJAX请求来删除脚本。

问题回答

看起来您正试图用Javascript调用ASP代码。这行不通。

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





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签