急急急!!!GridView无法更新数据!!!急急急
全部都是向导生成的,但无法跟新数据。手写代码不现实,因为GridView的数量很多很多。<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="pID"
DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="pID" HeaderText="pID" InsertVisible="False" ReadOnly="True"
SortExpression="pID" />
<asp:BoundField DataField="pNameCN" HeaderText="pNameCN" SortExpression="pNameCN" />
<asp:BoundField DataField="pNameEN" HeaderText="pNameEN" SortExpression="pNameEN" />
<asp:BoundField DataField="pmf" HeaderText="pmf" SortExpression="pmf" />
<asp:BoundField DataField="pAlias" HeaderText="pAlias" SortExpression="pAlias" />
<asp:BoundField DataField="remark" HeaderText="remark" SortExpression="remark" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:DftrDCPConnectionString %>" DeleteCommand="DELETE FROM [tProduct] WHERE [pID] = @original_pID AND [pNameCN] = @original_pNameCN AND [pNameEN] = @original_pNameEN AND [pmf] = @original_pmf AND [pAlias] = @original_pAlias AND [remark] = @original_remark"
InsertCommand="INSERT INTO [tProduct] ([pNameCN], [pNameEN], [pmf], [pAlias], [remark]) VALUES (@pNameCN, @pNameEN, @pmf, @pAlias, @remark)"
OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM [tProduct] WHERE ([pID] = @pID)"
UpdateCommand="UPDATE [tProduct] SET [pNameCN] = @pNameCN, [pNameEN] = @pNameEN, [pmf] = @pmf, [pAlias] = @pAlias, [remark] = @remark WHERE [pID] = @original_pID AND [pNameCN] = @original_pNameCN AND [pNameEN] = @original_pNameEN AND [pmf] = @original_pmf AND [pAlias] = @original_pAlias AND [remark] = @original_remark">
<DeleteParameters>
<asp:Parameter Name="original_pID" Type="Int64" />
<asp:Parameter Name="original_pNameCN" Type="String" />
<asp:Parameter Name="original_pNameEN" Type="String" />
<asp:Parameter Name="original_pmf" Type="String" />
<asp:Parameter Name="original_pAlias" Type="String" />
<asp:Parameter Name="original_remark" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="pNameCN" Type="String" />
<asp:Parameter Name="pNameEN" Type="String" />
<asp:Parameter Name="pmf" Type="String" />
<asp:Parameter Name="pAlias" Type="String" />
<asp:Parameter Name="remark" Type="String" />
<asp:Parameter Name="original_pID" Type="Int64" />
<asp:Parameter Name="original_pNameCN" Type="String" />
<asp:Parameter Name="original_pNameEN" Type="String" />
<asp:Parameter Name="original_pmf" Type="String" />
<asp:Parameter Name="original_pAlias" Type="String" />
<asp:Parameter Name="original_remark" Type="String" />
</UpdateParameters>
<SelectParameters>
<asp:QueryStringParameter Name="pID" QueryStringField="pID" Type="Int64" />
</SelectParameters>
<InsertParameters>
<asp:Parameter Name="pNameCN" Type="String" />
<asp:Parameter Name="pNameEN" Type="String" />
<asp:Parameter Name="pmf" Type="String" />
<asp:Parameter Name="pAlias" Type="String" />
<asp:Parameter Name="remark" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class UCs_ProductInfo : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
--------------------编程问答-------------------- 关键代码不都贴出来 谁知道是什么回事 。。。。。。。 --------------------编程问答-------------------- 怪问题啊,如果我换张表则就能更新了,为什么啊
两张表除了字段名字不一样以外其他都一样。 --------------------编程问答-------------------- 我没写代码啊,都是用向导生成的啊 --------------------编程问答-------------------- 我调试看了一下, GridView1里面所有的属性都显示:由于以前的函数求值超时,函数求值被禁用。必须继续执行才能重新启用函数求值。
高手救我啊,这到底是为什么啊,如何解决 --------------------编程问答-------------------- 把电脑重启一下重新托个GridView。 --------------------编程问答-------------------- 眼都花了,帮顶 --------------------编程问答-------------------- 看不出问题所在,你要深入调试一下了。 --------------------编程问答-------------------- 看的跟天上的星星一样 --------------------编程问答-------------------- 因为NULL = NULL则总是返回False
所以UpdateCommand="UPDATE [tProduct] SET [pNameCN] = @pNameCN, [pNameEN] = @pNameEN, [pmf] = @pmf, [pAlias] = @pAlias, [remark] = @remark WHERE [pID] = @original_pID AND [pNameCN] = @original_pNameCN AND [pNameEN] = @original_pNameEN AND [pmf] = @original_pmf AND [pAlias] = @original_pAlias AND [remark] = @original_remark">
不行,应该为:UpdateCommand="UPDATE [tProduct] SET [pNameCN] = @pNameCN, [pNameEN] = @pNameEN, [pmf] = @pmf, [pAlias] = @pAlias, [remark] = @remark WHERE [pID] = @original_pID">
假定pID为该数据库上的主键。
以上或许有所帮助~~
--------------------编程问答-------------------- 有点晕,这些代码! --------------------编程问答-------------------- 是报错了还是没有更新到?
补充:.NET技术 , ASP.NET