ObjectDataSource“ObjectDataSource1”未能找到带参数的非泛型方法
这个问题报错,因为参数对应不上,多了或者少了。或者是转换成模版时,Bind,和Eval没设置好,只有Bind是双向的,所以看是否update,insert方法设置了Eval
今天不是说这问题,是另外一个很类似的。
ObjectDataSource“ObjectDataSource1”未能找到接受。。。开始以为一样,不过它后面没有报参数出错的。
Code
<UpdateParameters>
<asp:Parameter Name="Company" Type="String" />
<asp:Parameter Name="GuestName" Type="String" />
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="Contents" Type="String" />
<asp:Parameter Name="Address" Type="String" />
<asp:Parameter Name="Tel" Type="String" />
<asp:Parameter Name="Mobile" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="QQ" Type="String" />
..//这里省了部分参数
</UpdateParameters>
<UpdateParameters>
<asp:Parameter Name="Company" Type="String" />
<asp:Parameter Name="GuestName" Type="String" />
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="Contents" Type="String" />
<asp:Parameter Name="Address" Type="String" />
<asp:Parameter Name="Tel" Type="String" />
<asp:Parameter Name="Mobile" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="QQ" Type="String" />
..//这里省了部分参数
</UpdateParameters>
因为objectDataSource方法绑定,上面页面的这代码会自动生成,关键就在这里。
Code
public static void UpdateLeaveword(string Company, string GuestName, string Title, string Contents,string Address, string Tel, string Mobile, string Email, string QQ, string PostCode, int Replayid, string ReplayContent, int Id, DateTime CreateDate,DateTime ReplayDate, string IpAddress)
//这里变量参数主要要和ORM映射的实体类要一致,例如大小写一致
{
LeaveWord leaveword = FetchEntityByKey(Id);
leaveword.Address = Address;
leaveword.Company = Company;
leaveword.Contents = Contents;
leaveword.Email = Email;
leaveword.GuestName = GuestName;
leaveword.Title = Title;
leaveword.Tel = Tel;
leaveword.ReplayContent = ReplayContent;
leaveword.QQ = QQ;
leaveword.PostCode = PostCode;
leaveword.Mobile = Mobile;
leaveword.ReplayId = Replayid;
if (db.LeaveWord.GetModifiedMembers(leaveword) != null)
{
string sql = string.Format("update leaveword set company='{0}',guestName='{1}',title='{2}',"
+ "contents='{3}',address='{4}',tel='{5}',mobile='{6}',email='{7}',qq='{8}',postcode='{9}',replayid={10},replaycontent='{11}',createdate='{12}',replaydate='{13}',ipaddress='{14}' where id={15}"
, Company, GuestName, Title, Contents, Address, Tel, Mobile, Email, QQ, PostCode, Replayid, ReplayContent, CreateDate, ReplayDate, IpAddress, Id);
if (db.ExecuteCommand(sql) > 0)
{
db.Refres(RefreshMode.OverwriteCurrentValues);
}
}
else { return; }
}
//这里是后台更新的方法,当然可以直接封装参数后,db.Submitchange(),为了对应objectdatasource的前台方法绑定,设置了更新的参数,关键看变量我们习惯是小写,这里要对应数据库表,应该是对应ORM框架的,所以要一致,开头要大写。这里搞好后,那个报错就会消失的,不知道是否是ORM框架映射的一个小BUG。
public static void UpdateLeaveword(string Company, string GuestName, string Title, string Contents,string Address, string Tel, string Mobile, string Email, string QQ, string PostCode, int Replayid, string ReplayContent, int Id, DateTime CreateDate,DateTime ReplayDate, string IpAddress)
//这里变量参数主要要和ORM映射的实体类要一致,例如大小写一致
{
LeaveWord leaveword = FetchEntityByKey(Id);
leaveword.Address = Address;
leaveword.Company = Company;
leaveword.Contents = Contents;
leaveword.Email = Email;
leaveword.GuestName = GuestName;
leaveword.Title = Title;
leaveword.Tel = Tel;
leaveword.ReplayContent = ReplayContent;
leaveword.QQ = QQ;
leaveword.PostCode = PostCode;
leaveword.Mobile = Mobile;
leaveword.ReplayId = Replayid;
if (db.LeaveWord.GetModifiedMembers(leaveword) != null)
{
string sql = string.Format("update leaveword set company='{0}',guestName='{1}',title='{2}',"
+ "contents='{3}',address='{4}',tel='{5}',mobile='{6}',email='{7}',qq='{8}',postcode='{9}',replayid={10},replaycontent='{11}',createdate='{12}',replaydate='{13}',ipaddress='{14}' where id={15}"
, Company, GuestName, Title, Contents, Address, Tel, Mobile, Email, QQ, PostCode, Replayid, ReplayContent, CreateDate, ReplayDate, IpAddress, Id);
if (db.ExecuteCommand(sql) > 0)
{
db.Refres(RefreshMode.OverwriteCurrentValues);
}
}
else { return; }
}
//这里是后台更新的方法,当然可以直接封装参数后,db.Submitchange(),为了对应objectdatasource的前台方法绑定,设置了更新的参数,关键看变量我们习惯是小写,这里要对应数据库表,应该是对应ORM框架的,所以要一致,开头要大写。这里搞好后,那个报错就会消失的,不知道是否是ORM框架映射的一个小BUG。
这样问题解决了,detailview,gridview等只要用到前台方法绑定,用了ORM框架的,都要注意这些问题