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;
}
点击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;
}
解决方案 »
- repeat+if
- 打开项目输入密码?
- 请教小问题~~无法从“int”转换为 CommandType
- 如何实现asp:FileUpload控件选择图片文件后,就立即在页面显示出该图片?路径可为本地的
- 新手请教问题 DataGrid 分页问题
- asp.net想用多选下拉框该怎么做啊!
- 没人愿意帮我呀,只好再问了,如何遍历datagrid中的checkbox!
- 请问关于类与类之间改如何访问?????????????????????
- 很烦恼的问题:怎样给RadioButtonList控件里面的每个input加个onClick(客户端的)属性
- 帮我解决一下这个问题
- 如何在web application中运用Profile 的问题?
- Response.Write("")导致页面样式丢失的问题?
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>
可以对断代码解释下吗?
-->
<asp:Parameter Name="RecordID" Type="Int32" />try it!
Thank you all the same.
试了,没有效果。THANKS ALL THE SAME
---------------------
断代码: 给代码加断点(我的叫法)
他的问题出在没有Update的按钮,Command="Edit"只是打开编辑模式,编辑完后需要执行Commend="Update"才行,但是他没有写Command="update"的Control,故无法更新