我有网格视图绑定sql数据源并添加字段以更新网格视图中的数据,但它没有做任何更新,也没有出现错误,我不知道错误在哪里
SQL存储过程:
ALTER proc [dbo].[GetNewswithType]
As
Begin
Select News.Id,News.Type_Id,
News.Header,News.HText,News.DText,News.Active,News.Add_Date,
NewsType.Type_AR,NewsType.Type_EN
From News
Inner Join NewsType On
NewsType.Id=News.Type_Id
End
ALTER Proc [dbo].[UpdateNews]
(
@Id Int
,@Header Nvarchar(50)
,@HText Nvarchar(Max)
,@DText Nvarchar(Max)
,@Type_Id Int
,@Active Bit
)
AS
BEGIN
Update News Set
@Header =Header
,@HText =HText
,@DText =DText
,@Type_Id=Type_Id
,@Active =Active
WHERE @Id=Id
END
ASPX页面:
<div class="m10">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px"
CellPadding="4" DataKeyNames="Id" DataSourceID="SDSNews" ForeColor="Black"
GridLines="Vertical"
onselectedindexchanged="GridView1_SelectedIndexChanged"
onselectedindexchanging="GridView1_SelectedIndexChanging"
onpageindexchanging="GridView1_PageIndexChanging" AllowPaging="True"
onrowupdated="GridView1_RowUpdated"
onrowdatabound="GridView1_RowDataBound">
<FooterStyle BackColor="#CCCC99" />
<RowStyle BackColor="#F7F7DE" />
<Columns>
<asp:CommandField HeaderText="Function" ShowEditButton="True" />
<asp:BoundField DataField="Id" HeaderText="Id" SortExpression="Id"
Visible="False" />
<asp:BoundField DataField="Header" HeaderText="Header"
SortExpression="Header" />
<asp:BoundField DataField="HText" HeaderText="HomeText"
SortExpression="HText" />
<asp:BoundField DataField="DText" HeaderText="DetailsText"
SortExpression="DText" />
<asp:BoundField DataField="Type_Id" HeaderText="TypeNumber"
SortExpression="Type_Id" />
<asp:BoundField DataField="Type_AR" HeaderText="Type_AR"
SortExpression="Type_AR" InsertVisible="False" ReadOnly="True" />
<asp:BoundField DataField="Type_EN" HeaderText="Type_EN"
SortExpression="Type_EN" InsertVisible="False" ReadOnly="True" />
<asp:CheckBoxField DataField="Active" HeaderText="Active"
SortExpression="Active" />
<asp:BoundField DataField="Add_Date" HeaderText="Add_Date"
SortExpression="Add_Date" InsertVisible="False" ReadOnly="True" />
</Columns>
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="SDSNews" runat="server"
ConnectionString="Data Source=ELARABY-1EACFA3\SQLEXPRESS;Initial Catalog=ElarabyGroup;Integrated Security=True"
ProviderName="System.Data.SqlClient" SelectCommand="GetNewswithType"
SelectCommandType="StoredProcedure" UpdateCommand="UpdateNews"
UpdateCommandType="StoredProcedure">
<UpdateParameters>
<asp:ControlParameter ControlID="GridView1" Name="Id"
PropertyName="SelectedValue" Type="Int32" />
<asp:ControlParameter ControlID="GridView1" Name="Header"
PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="GridView1" Name="HText"
PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="GridView1" Name="DText"
PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="GridView1" Name="Type_Id"
PropertyName="SelectedValue" Type="Int32" />
<asp:ControlParameter ControlID="GridView1" Name="Active"
PropertyName="SelectedValue" Type="Boolean" />
</UpdateParameters>
</asp:SqlDataSource>
</div>
答案 0 :(得分:1)
在更新过程中添加一些代码以确定是否正在调用它:
Logging
的表格(或您选择的任何名称),其中包含一个名为Message
的列(或您选择的任何名称)UpdateNews
程序中添加一行INSERT INTO [dbo].[Logging] (Message) VALUES ('Procedure Called')
。如果您愿意,可以记录传入的参数的值。通过执行此操作,您可以确定是否实际调用了存储过程。另一种选择是使用Sql Server Profiler来确定这一点。如果您可以确定 调用存储过程,那么就会出现问题,通过记录参数,您可以“手动调用”它以找出原因。
更有可能的是,永远不会调用存储过程,您如何告诉网格将更改保留回数据库?查看this tutorial,我建议您的更新不会触发“保存”。