简体   繁体   English

网格视图更新

[英]grid view update

I had grid view which bind sql data source and added field to update data in grid view but it did not do any update and no error appeared and I did not know where the error 我有绑定SQL数据源的网格视图,并添加了字段以更新网格视图中的数据,但是它没有进行任何更新,也没有出现错误,我也不知道错误在哪里

SQL Stored Procedures: 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 Page: 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>

Add some code to your update procedure to determine if it's being called: 在更新过程中添加一些代码,以确定是否正在调用它:

  1. Create a table called Logging (or any name of your choice) that has a column called Message (again, or any name of your choice) 创建一个名为Logging (或您选择的任何名称)的表,该表具有一个名为Message (同样,或您选择的任何名称)的列。
  2. Add a line to your UpdateNews procedure to INSERT INTO [dbo].[Logging] (Message) VALUES ('Procedure Called') . UpdateNews过程中添加一行到INSERT INTO [dbo].[Logging] (Message) VALUES ('Procedure Called') You could log the values of the parameters passed in, if you so wished. 如果愿意,您可以记录传入的参数的值。

By doing this you can determine if the stored procedure is actually being called or not. 通过执行此操作,您可以确定是否实际调用了存储过程。 The other option is to use Sql Server Profiler to determine this. 另一个选择是使用Sql Server Profiler来确定这一点。 If you can determine that it is calling the stored procedure, then something is going wrong in there and by logging the parameters you can "hand call" it to find out why. 如果可以确定它正在调用存储过程,则那里出了点问题,并且通过记录参数可以“手动调用”它以找出原因。

More likely is that the stored procedure is never being called, how are you telling the grid to persist the changes back out to the database? 更有可能是从未调用过存储过程,如何告诉网格将更改持久化回数据库? Looking at this tutorial , I would suggest that your updates are not triggering a "save". 查看本教程 ,我建议您的更新不会触发“保存”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM