我用gridview绑定sql数据库进行数据更新,更新的时候没有提示任何错误,但是就是数据不发生变化!!
代码如下:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
AutoGenerateEditButton="True" DataKeyNames="code" DataSourceID="SqlDataSource1"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged" PageSize="30" OnRowEditing="GridView1_RowEditing1">
<Columns>
<asp:BoundField DataField="code" HeaderText="code" ReadOnly="True" SortExpression="code" />
<asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
<asp:BoundField DataField="ename" HeaderText="ename" SortExpression="ename" />
<asp:BoundField DataField="omosa" HeaderText="omosa" SortExpression="omosa" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:code-enameConnectionString %>"
DeleteCommand="DELETE FROM [ename] WHERE [code] = @original_code" InsertCommand="INSERT INTO [ename] ([code], [name], [ename], [omosa]) VALUES (@code, @name, @ename, @omosa)"
SelectCommand="SELECT * FROM [ename]" UpdateCommand="UPDATE ename SET name = @name, ename = @ename, omosa = @omosa WHERE (code = @original_code)" OldValuesParameterFormatString="original_{0}" OnUpdating="SqlDataSource1_Updating">
<DeleteParameters>
<asp:Parameter Name="original_code" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="ename" Type="String" />
<asp:Parameter Name="omosa" Type="Decimal" />
<asp:Parameter Name="original_code" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="code" Type="String" />
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="ename" Type="String" />
<asp:Parameter Name="omosa" Type="Decimal" />
</InsertParameters>
</asp:SqlDataSource>
但是测试sql数据的时候可以更新成功的,奇怪啊,高手帮忙!