ASP.NET 2.0 FORMVIEW 采用OBJECTDATASOURCE 数据源,下面是BLL更新部分的代码。
点击FORMVIEW 的编辑按钮,可以进入编辑状态,再点击更新时,不提示跟新失败,但是数据确不更新。
多方查找错误地方,无奈失败。
恳请好心人帮忙看下代码是不是有问题。谢谢。[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
    public bool UpdateRecord(int? 主动, int? 对手, int? 客户, DateTime 下次, int? 地点, string 记录, DateTime 时间, int? 工具, string 主题, int original_RecordID)
    {
        WZNJSY.RecordsDataTable Records = Adapter.GetRecordsByCustomerContactID(original_RecordID);
        if (Records.Count == 0)
            // no matching record found, return false
            return false;        WZNJSY.RecordsRow Record = Records[0];        Record.主动 = 主动.Value;
        Record.对手 = 对手.Value;
        Record.客户 = 客户.Value;
        if (下次 == null) Record.Set下次Null(); else Record.下次 = 下次;
        Record.地点 = 地点.Value;
        if (记录 == null) Record.Set记录Null(); else Record.记录 = 记录;
        if (时间 == null) Record.Set时间Null(); else Record.时间 =时间;
        Record.工具 = 工具.Value;
        if (主题 == null) Record.Set主题Null(); else Record.主题 =主题;        // Update the product record
        int rowsAffected = Adapter.Update(Record);        // Return true if precisely one row was inserted, otherwise false
        return rowsAffected == 1;
    }

解决方案 »

  1.   

    下面是ASPX页面的代码   <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DeleteMethod="DeleteRecord"
                InsertMethod="AddRecord" OldValuesParameterFormatString="original_{0}" SelectMethod="getRecords"
                TypeName="RecordsBLL" UpdateMethod="UpdateRecord">
                <DeleteParameters>
                    <asp:Parameter Name="RecordID" Type="Int32" />
                </DeleteParameters>
                <UpdateParameters>
                    <asp:Parameter Name="主动" Type="Int32" />
                    <asp:Parameter Name="对手" Type="Int32" />
                    <asp:Parameter Name="客户" Type="Int32" />
                    <asp:Parameter Name="下次" Type="DateTime" />
                    <asp:Parameter Name="地点" Type="Int32" />
                    <asp:Parameter Name="记录" Type="String" />
                    <asp:Parameter Name="时间" Type="DateTime" />
                    <asp:Parameter Name="工具" Type="Int32" />
                    <asp:Parameter Name="主题" Type="String" />
                    <asp:Parameter Name="original_RecordID" Type="Int32" />
                </UpdateParameters>
                <InsertParameters>
                    <asp:Parameter Name="主动" Type="Int32" />
                    <asp:Parameter Name="对手" Type="Int32" />
                    <asp:Parameter Name="客户" Type="Int32" />
                    <asp:Parameter Name="下次" Type="DateTime" />
                    <asp:Parameter Name="地点" Type="Int32" />
                    <asp:Parameter Name="记录" Type="String" />
                    <asp:Parameter Name="时间" Type="DateTime" />
                    <asp:Parameter Name="主题" Type="String" />
                    <asp:Parameter Name="工具" Type="Int32" />
                </InsertParameters>
            </asp:ObjectDataSource>
            <asp:FormView ID="FormView1" runat="server" DataKeyNames="RecordID" DataSourceID="ObjectDataSource1">
                <EditItemTemplate>
                    RecordID:
                    <asp:Label ID="RecordIDLabel1" runat="server" Text='<%# Eval("RecordID") %>'></asp:Label><br />
                    主题:
                    <asp:TextBox ID="主题TextBox" runat="server" Text='<%# Bind("主题") %>'>
                    </asp:TextBox><br />
                    记录:
                    <asp:TextBox ID="记录TextBox" runat="server" Text='<%# Bind("记录") %>'>
                    </asp:TextBox><br />
                    工具:
                    <asp:TextBox ID="工具TextBox" runat="server" Text='<%# Bind("工具") %>'>
                    </asp:TextBox><br />
                    主动:
                    <asp:TextBox ID="主动TextBox" runat="server" Text='<%# Bind("主动") %>'>
                    </asp:TextBox><br />
                    时间:
                    <asp:TextBox ID="时间TextBox" runat="server" Text='<%# Bind("时间") %>'>
                    </asp:TextBox><br />
                    下次:
                    <asp:TextBox ID="下次TextBox" runat="server" Text='<%# Bind("下次") %>'>
                    </asp:TextBox><br />
                    地点:
                    <asp:TextBox ID="地点TextBox" runat="server" Text='<%# Bind("地点") %>'>
                    </asp:TextBox><br />
                    对手:
                    <asp:TextBox ID="对手TextBox" runat="server" Text='<%# Bind("对手") %>'>
                    </asp:TextBox><br />
                    客户:
                    <asp:TextBox ID="客户TextBox" runat="server" Text='<%# Bind("客户") %>'>
                    </asp:TextBox><br />
                    <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
                        Text="更新">
                    </asp:LinkButton>
                    <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                        Text="取消">
                    </asp:LinkButton>
                </EditItemTemplate>
                <InsertItemTemplate>
                    主题:
                    <asp:TextBox ID="主题TextBox" runat="server" Text='<%# Bind("主题") %>'>
                    </asp:TextBox><br />
                    记录:
                    <asp:TextBox ID="记录TextBox" runat="server" Text='<%# Bind("记录") %>'>
                    </asp:TextBox><br />
                    工具:
                    <asp:TextBox ID="工具TextBox" runat="server" Text='<%# Bind("工具") %>'>
                    </asp:TextBox><br />
                    主动:
                    <asp:TextBox ID="主动TextBox" runat="server" Text='<%# Bind("主动") %>'>
                    </asp:TextBox><br />
                    时间:
                    <asp:TextBox ID="时间TextBox" runat="server" Text='<%# Bind("时间") %>'>
                    </asp:TextBox><br />
                    下次:
                    <asp:TextBox ID="下次TextBox" runat="server" Text='<%# Bind("下次") %>'>
                    </asp:TextBox><br />
                    地点:
                    <asp:TextBox ID="地点TextBox" runat="server" Text='<%# Bind("地点") %>'>
                    </asp:TextBox><br />
                    对手:
                    <asp:TextBox ID="对手TextBox" runat="server" Text='<%# Bind("对手") %>'>
                    </asp:TextBox><br />
                    客户:
                    <asp:TextBox ID="客户TextBox" runat="server" Text='<%# Bind("客户") %>'>
                    </asp:TextBox><br />
                    <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                        Text="插入">
                    </asp:LinkButton>
                    <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                        Text="取消">
                    </asp:LinkButton>
                </InsertItemTemplate>
                <ItemTemplate>
                    RecordID:
                    <asp:Label ID="RecordIDLabel" runat="server" Text='<%# Eval("RecordID") %>'></asp:Label><br />
                    主题:
                    <asp:Label ID="主题Label" runat="server" Text='<%# Bind("主题") %>'></asp:Label><br />
                    记录:
                    <asp:Label ID="记录Label" runat="server" Text='<%# Bind("记录") %>'></asp:Label><br />
                    工具:
                    <asp:Label ID="工具Label" runat="server" Text='<%# Bind("工具") %>'></asp:Label><br />
                    主动:
                    <asp:Label ID="主动Label" runat="server" Text='<%# Bind("主动") %>'></asp:Label><br />
                    时间:
                    <asp:Label ID="时间Label" runat="server" Text='<%# Bind("时间") %>'></asp:Label><br />
                    下次:
                    <asp:Label ID="下次Label" runat="server" Text='<%# Bind("下次") %>'></asp:Label><br />
                    地点:
                    <asp:Label ID="地点Label" runat="server" Text='<%# Bind("地点") %>'></asp:Label><br />
                    对手:
                    <asp:Label ID="对手Label" runat="server" Text='<%# Bind("对手") %>'></asp:Label><br />
                    客户:
                    <asp:Label ID="客户Label" runat="server" Text='<%# Bind("客户") %>'></asp:Label><br />
                    <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit"
                        Text="编辑">
                    </asp:LinkButton>
                    <asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete"
                        Text="删除">
                    </asp:LinkButton>
                    <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New"
                        Text="新建">
                    </asp:LinkButton>
                </ItemTemplate>
            </asp:FormView>
      

  2.   

    TO:include_me(丁一) 
    可以对断代码解释下吗?
      

  3.   

    查看过数据库,update后,数据库中的数据没有改变。
      

  4.   

    <asp:Parameter Name="original_RecordID" Type="Int32" />
    -->
    <asp:Parameter Name="RecordID" Type="Int32" />try it!
      

  5.   

    treble_h, Thanks。 I tried, but it does not work, either.
    Thank you all the same.
      

  6.   

    你的delete的parameter为什么是RecordID?你的函数仅接受orginial_RecordID啊,应该改为original_RecordID吧。
      

  7.   

    To;cat_hsfz
    试了,没有效果。THANKS ALL THE SAME
      

  8.   

    wznjsy() 
    ---------------------
    断代码: 给代码加断点(我的叫法)
      

  9.   

    这个小贱人,自己知道答案了就不说了,大家以后不用回复他问题了
    他的问题出在没有Update的按钮,Command="Edit"只是打开编辑模式,编辑完后需要执行Commend="Update"才行,但是他没有写Command="update"的Control,故无法更新