📄 admin_delete_database.aspx
字号:
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Globalization" %>
<HTML>
<script language="VB" runat="server">
Dim MyConnection As SqlConnection
Sub Page_Load(Sender As Object, E As EventArgs)
MyConnection = New _
SqlConnection("workstation id=SONGWEI;packet size=4096;user id=sa;password=sql;data source=SONGWEI;persist se" & _
"curity info=False;initial catalog=vodweb")
if pagemode2.checked then
MyDataGrid.pagerstyle.mode=pagermode.numericpages
else
MyDataGrid.pagerstyle.mode=pagermode.nextprev
MyDataGrid.pagerstyle.prevpagetext="上一页"
MyDataGrid.pagerstyle.nextpagetext="下一页"
end if
If Not (IsPostBack)
BindGrid("userid")
End If
End Sub
Sub MyDataGrid_Delete(sender As Object, E As DataGridCommandEventArgs)
Dim deleteCmd As String = "DELETE FROM reg WHERE userid = @Userid;"
Dim myCommand As SqlCommand = New SqlCommand(deleteCmd, _
myConnection)
myCommand.Parameters.Add(New SqlParameter("@Userid", _
SqlDbType.Char, 10))
' Initialize the SqlCommand "@Id" parameter to the ID of the row
' that was clicked.
myCommand.Parameters("@Userid").Value = _
MyDataGrid.DataKeys(CInt(E.Item.ItemIndex))
' Connect to the database and delete the specified row.
myCommand.Connection.Open()
' Test whether the delete was accomplished, and display the
' appropriate message to the user.
Try
myCommand.ExecuteNonQuery()
Message.InnerHtml = "<b>删除记录成功</b><br>"
Catch ex As SqlException
Message.InnerHtml = "ERROR: Could not delete record"
Message.Style("color") = "red"
End Try
' Close the connection.
myCommand.Connection.Close()
' Rebind the DataGrid to show the updated information.
BindGrid("userid")
End Sub
Sub BindGrid(SortField as string)
Dim DS As DataSet
Dim MyCommand As SqlDataAdapter
MyCommand = new SqlDataAdapter("select * from reg", MyConnection)
DS = new DataSet()
MyCommand.Fill(DS, "用户信息")
dim source as dataview=DS.Tables("用户信息").DefaultView
MyDataGrid.DataSource=source
source.sort=SortField
MyDataGrid.DataBind()
End Sub
sub MyDataGrid_PageIndexChanged(sender as object ,e as datagridpagechangedeventargs)
MyDataGrid.currentpageindex=e.newpageindex
BindGrid("userid")
end sub
Sub MyDataGrid_Sort(Src As Object, E As DataGridSortCommandEventArgs)
BindGrid(E.SortExpression)
End Sub
</script>
<body style="FONT: 10pt verdana">
<form id="Form1" runat="server">
<h3><font face="Verdana">管理员删除数据库记录</font></h3>
<span id="Message" runat="server" EnableViewState="false"></span>
<p><ASP:DATAGRID id="MyDataGrid" runat="server" OnDeleteCommand="MyDataGrid_Delete" AllowSorting="True"
AllowPaging="True" OnSortCommand="MyDataGrid_Sort" OnPageIndexChanged="MyDataGrid_PageIndexChanged"
DataKeyField="userid" HeaderStyle-BackColor="#aaaadd" Font-Size="8pt" Font-Name="Verdana"
CellPadding="3" BorderColor="Black" BackColor="#CCCCFF" Width="800px" Font-Names="Verdana">
<HeaderStyle BackColor="#AAAADD"></HeaderStyle>
<Columns>
<asp:ButtonColumn Text="删除" CommandName="Delete"></asp:ButtonColumn>
</Columns>
</ASP:DATAGRID>
<center>页码模式:
<asp:radiobutton id="pagemode1" Text="数字模式" GroupName="页码模式" Checked="True" AutoPostBack="True" Runat="server"></asp:radiobutton><asp:radiobutton id="pagemode2" Text="上下页模式" GroupName="页码模式" Checked="True" AutoPostBack="True"
Runat="server"></asp:radiobutton></center>
</form>
</body>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -