求助:VS2005做ASPX页面,可以插入数据,但不能更新和删除
本人初学者,请教各位达人,希望热心相助,先谢啦!!近期用VS 2005+sql server2005 做动态网站,DetailsView可以插入数据到数据库,点编辑后可以进入更新页面,修改数据点更新后,刷新网页,但是没有将数据更新到数据库,点删除也是只更新页面不删除数据。把页面代码贴在下面,请求达人看看是什么问题:
<%@ Page Language="VB" MasterPageFile="~/MasterPage3.master" AutoEventWireup="false" CodeFile="admin.aspx.vb" Inherits="HTML_yhsh" title="未标题-1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<table width="1024">
<tr>
<td colspan="3" style="height: 202px" >
<asp:Image ID="Image1" runat="server" ImageUrl="~/Image/yh_ba.jpg" /></td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffff" style="color: #ffffff" width="1024">
<tr>
<td style="height: 32px; background-color: #000000; vertical-align: top; text-align: center;" colspan="2" rowspan="3">
<table width="100%">
<tr>
<td style="HEIGHT: 252px">
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:E:\HRWEB\APP_DATA\ASPNETDB.MDFConnectionString10 %>"
DeleteCommand="DELETE FROM [WebNews] WHERE [news_ID] = @original_news_ID AND [news_Name] = @original_news_Name AND [news_From] = @original_news_From AND [news_Eidt] = @original_news_Eidt AND [news_Text] = @original_news_Text AND [news_Class] = @original_news_Class AND [news_time] = @original_news_time"
InsertCommand="INSERT INTO [WebNews] ([news_Name], [news_From], [news_Eidt], [news_Text], [news_Class], [news_time]) VALUES (@news_Name, @news_From, @news_Eidt, @news_Text, @news_Class, @news_time)"
OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM [WebNews]"
UpdateCommand="UPDATE [WebNews] SET [news_Name] = @news_Name, [news_From] = @news_From, [news_Eidt] = @news_Eidt, [news_Text] = @news_Text, [news_Class] = @news_Class, [news_time] = @news_time WHERE [news_ID] = @original_news_ID AND [news_Name] = @original_news_Name AND [news_From] = @original_news_From AND [news_Eidt] = @original_news_Eidt AND [news_Text] = @original_news_Text AND [news_Class] = @original_news_Class AND [news_time] = @original_news_time">
<DeleteParameters>
<asp:Parameter Name="original_news_ID" Type="Int32" />
<asp:Parameter Name="original_news_Name" Type="String" />
<asp:Parameter Name="original_news_From" Type="String" />
<asp:Parameter Name="original_news_Eidt" Type="String" />
<asp:Parameter Name="original_news_Text" Type="String" />
<asp:Parameter Name="original_news_Class" Type="String" />
<asp:Parameter Name="original_news_time" Type="DateTime" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="news_Name" Type="String" />
<asp:Parameter Name="news_From" Type="String" />
<asp:Parameter Name="news_Eidt" Type="String" />
<asp:Parameter Name="news_Text" Type="String" />
<asp:Parameter Name="news_Class" Type="String" />
<asp:Parameter Name="news_time" Type="DateTime" />
<asp:Parameter Name="original_news_ID" Type="Int32" />
<asp:Parameter Name="original_news_Name" Type="String" />
<asp:Parameter Name="original_news_From" Type="String" />
<asp:Parameter Name="original_news_Eidt" Type="String" />
<asp:Parameter Name="original_news_Text" Type="String" />
<asp:Parameter Name="original_news_Class" Type="String" />
<asp:Parameter Name="original_news_time" Type="DateTime" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="news_Name" Type="String" />
<asp:Parameter Name="news_From" Type="String" />
<asp:Parameter Name="news_Eidt" Type="String" />
<asp:Parameter Name="news_Text" Type="String" />
<asp:Parameter Name="news_Class" Type="String" />
<asp:Parameter Name="news_time" Type="DateTime" />
</InsertParameters>
</asp:SqlDataSource>
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="news_ID"
DataSourceID="SqlDataSource1" Height="50px" Width="125px">
<Fields>
<asp:BoundField DataField="news_ID" HeaderText="news_ID" InsertVisible="False" ReadOnly="True"
SortExpression="news_ID" />
<asp:BoundField DataField="news_Name" HeaderText="news_Name" SortExpression="news_Name" />
<asp:BoundField DataField="news_From" HeaderText="news_From" SortExpression="news_From" />
<asp:BoundField DataField="news_Eidt" HeaderText="news_Eidt" SortExpression="news_Eidt" />
<asp:BoundField DataField="news_Text" HeaderText="news_Text" SortExpression="news_Text" />
<asp:BoundField DataField="news_Class" HeaderText="news_Class" SortExpression="news_Class" />
<asp:BoundField DataField="news_time" HeaderText="news_time" SortExpression="news_time" />
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowInsertButton="True" />
</Fields>
</asp:DetailsView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"></asp:ObjectDataSource>
</td>
</tr>
</table>
</td>
</tr>
<tr>
</tr>
<tr>
</tr>
</table>
</asp:Content>
--------------------编程问答-------------------- 删除、更新后重新绑定没??? --------------------编程问答-------------------- --------------------编程问答--------------------
试试1#的方法 --------------------编程问答-------------------- 绑定多次了 --------------------编程问答-------------------- LZ 你这样的错误很明显,要断点追踪,看修改数据库的sql语句是否运行正常,你数据库修改没成功 数据绑定怎么会显示你想要的结果? --------------------编程问答-------------------- DetailsView编辑、删除实例
问题解决:解决方法 --------------------编程问答-------------------- ok --------------------编程问答-------------------- 但是没有将数据更新到数据库,点删除也是只更新页面不删除数据。
修改之后要从新绑定一下你的数据库
另外看看你的记录在数据库里有没有改变。
补充:.NET技术 , ASP.NET