我的新闻系统为什么只可以插入数据,但修改(更新)无效呢?
前台代码:<%@ Page Language="VB" AutoEventWireup="false" CodeFile="newsAdminDetail.aspx.vb" Inherits="news_newsAdminDetail" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head runat="server">
<title>无标题页</title>
<style type="text/css">
.STYLE1 {
font-family: "华文行楷";
font-size: 36px;
}
.STYLE2 {color: #FFFFFF}
.STYLE3 {
color: #FFFFFF;
font-size: 24px;
}
.STYLE5 {
color: #FFFFFF;
font-size: 14px;
font-weight: bold;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="141" colspan="2" background="../images/weiyong.gif"><div align="right" class="STYLE1">
<div align="center">
<p class="STYLE2">新闻公告</p>
<p align="right" class="STYLE3"> </p>
</div>
</div></td>
</tr>
<tr>
<td height="1" colspan="2" background="../images/line.jpg">
<asp:Button ID="Button1" runat="server" PostBackUrl="~/news/newsAdmin.aspx"
Text="回到登录管理页面" />
<asp:LoginStatus ID="LoginStatus1" runat="server" Font-Names="Arial Black"
Font-Size="10pt" ForeColor="White" LogoutAction="Redirect"
LogoutPageUrl="~/news/news.aspx" style="text-align: right" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:LoginView ID="LoginView1" runat="server">
<LoggedInTemplate>
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
Caption="新闻数据管理" CellPadding="4" DataSourceID="AccessDataSource1"
DefaultMode="Edit" ForeColor="#333333" GridLines="None" Height="50px"
Width="100%">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<CommandRowStyle BackColor="#D1DDF1" Font-Bold="True" />
<RowStyle BackColor="#EFF3FB" />
<FieldHeaderStyle BackColor="#DEE8F5" Font-Bold="True" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<Fields>
<asp:TemplateField HeaderText="类别">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server"
SelectedValue='<%# Bind("news_type") %>'>
<asp:ListItem>公告</asp:ListItem>
<asp:ListItem>新书</asp:ListItem>
<asp:ListItem>活动</asp:ListItem>
<asp:ListItem>学习资料</asp:ListItem>
<asp:ListItem>光盘</asp:ListItem>
<asp:ListItem>电影</asp:ListItem>
<asp:ListItem>其他</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList2" runat="server"
SelectedValue='<%# Bind("news_type") %>'>
<asp:ListItem>其他</asp:ListItem>
<asp:ListItem>活动</asp:ListItem>
<asp:ListItem>新书</asp:ListItem>
<asp:ListItem>公告</asp:ListItem>
<asp:ListItem>学习资料</asp:ListItem>
<asp:ListItem>电影</asp:ListItem>
<asp:ListItem>光盘</asp:ListItem>
</asp:DropDownList>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="日期">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("news_date") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:Label ID="Label1" runat="server" Text="<%# now() %>"></asp:Label>
</InsertItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="news_subject" HeaderText="标题" />
<asp:BoundField DataField="news_editor" HeaderText="编辑者" />
<asp:TemplateField HeaderText="内容">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Height="100px"
Text='<%# Bind("news_content") %>' TextMode="MultiLine" Width="450px"></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Height="100px"
Text='<%# Bind("news_content") %>' TextMode="MultiLine" Width="450px"></asp:TextBox>
</InsertItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" ShowInsertButton="True" />
</Fields>
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:DetailsView>
</LoggedInTemplate>
<AnonymousTemplate>
请您执行<asp:LoginStatus ID="LoginStatus2" runat="server" />
操作!
</AnonymousTemplate>
</asp:LoginView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/news.mdb"
DeleteCommand="DELETE FROM [newscenter] WHERE [news_id] = ?"
InsertCommand="INSERT INTO [newscenter] ( [news_type], [news_subject], [news_content], [news_editor]) VALUES (?, ?, ?, ?)"
SelectCommand="SELECT * FROM [newscenter] WHERE ([news_id] = ?)"
UpdateCommand="UPDATE [newscenter] SET [news_type] = ?, [news_date] = ?, [news_subject] = ?, [news_content] = ?, [news_editor] = ? WHERE [news_id] = ?">
<SelectParameters>
<asp:QueryStringParameter Name="news_id" QueryStringField="news_id"
Type="Int32" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="news_id" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="news_type" Type="String" />
<asp:Parameter Name="news_date" Type="DateTime" />
<asp:Parameter Name="news_subject" Type="String" />
<asp:Parameter Name="news_content" Type="String" />
<asp:Parameter Name="news_editor" Type="String" />
<asp:Parameter Name="news_id" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="news_type" Type="String" />
<asp:Parameter Name="news_subject" Type="String" />
<asp:Parameter Name="news_content" Type="String" />
<asp:Parameter Name="news_editor" Type="String" />
</InsertParameters>
</asp:AccessDataSource>
</td>
</tr>
<tr>
<td height="19" colspan="2" bgcolor="#009FC9"> </td>
</tr>
</table>
</form>
</body>
</html>
后台代码
Partial Class news_newsAdminDetail
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Request.QueryString("action") = "Insert" Then
CType(LoginView1.FindControl("DetailsView1"), DetailsView).DefaultMode = DetailsViewMode.Insert
End If
End Sub
Protected Sub AccessDataSource1_Inserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles AccessDataSource1.Inserted
Response.Redirect("newsAdmin.aspx")
End Sub
Protected Sub AccessDataSource1_Updated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles AccessDataSource1.Updated
Response.Redirect("newsAdmin.aspx")
End Sub
End Class
界面如下