| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 485 人关注过本帖
标题:我的新闻系统为什么只可以插入数据,但修改(更新)无效呢?
只看楼主 加入收藏
鸿鹄
Rank: 2
等 级:论坛游民
帖 子:51
专家分:10
注 册:2009-3-20
结帖率:75%
收藏
已结贴  问题点数:19 回复次数:1 
我的新闻系统为什么只可以插入数据,但修改(更新)无效呢?
前台代码:
<%@ 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">&nbsp;</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="回到登录管理页面" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <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">&nbsp;</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
界面如下
图片附件: 游客没有浏览图片的权限,请 登录注册
搜索更多相关主题的帖子: 系统 数据 
2010-05-02 14:04
f00a0
Rank: 2
等 级:论坛游民
帖 子:12
专家分:22
注 册:2010-4-5
收藏
得分:19 
要数据绑定的
2010-05-02 17:51
快速回复:我的新闻系统为什么只可以插入数据,但修改(更新)无效呢?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023647 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved