[求助]delete不到database records(参考www.asp101.com的sample做的)
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Data" %>
<HTML>
<script language="VB" runat="server">
Sub Page_Load(Sender As Object, E As EventArgs)
Dim objConn As New oleDbConnection
objConn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;"
objConn.ConnectionString+= "Data Source= " & Server.MapPath("Account.mdb")
ShowDataGrid()
End Sub
Sub ShowDataGrid()
Dim objCommand As oleDbCommand
Dim strSQLQuery As String
Dim objConn As New oleDbConnection
objConn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;"
objConn.ConnectionString+= "Data Source= " & Server.MapPath("Account.mdb")
strSQLQuery = "SELECT * FROM ordered;"
objCommand = New OleDbCommand(strSQLQuery, objConn)
objConn.Open()
OP.DataSource = objCommand.ExecuteReader(CommandBehavior.CloseConnection)
OP.DataBind()
objConn.Close()
End Sub
Sub Delete(source As Object, E As DataGridCommandEventArgs)
Dim objCommand As oleDbCommand
Dim strSQLQuery As String
Dim objConn As New oleDbConnection
objConn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;"
objConn.ConnectionString+= "Data Source= " & Server.MapPath("Account.mdb")
strSQLQuery = "DELETE FROM ordered WHERE No=" & OP.DataKeys(E.Item.ItemIndex) & ";"
objCommand = New OleDbCommand(strSQLQuery, objConn)
objConn.Open()
objCommand.ExecuteNonQuery()
objConn.Close()
ShowDataGrid()
End Sub
</script>
<body>
<form runat="server" ID="Form1">
<asp:DataGrid id="OP" runat="server" DataKeyField="No">
<Columns>
<asp:ButtonColumn Text="Delete" CommandName="Delete"></asp:ButtonColumn>
</Columns>
</asp:DataGrid>
</form>
<p>
</p>
</body>
</HTML>