我正在使用由ASP.net Web窗体应用程序上的ObjectDataSource支持的GridView。GridView从数据库中获取很多字段并显示它们。我只想对这些字段中的一个进行编辑,但是我已经遇到了一些问题。我对ObjectDataSource的更新命令如下所示:
public void UpdateRML(string itemCode, int newRML)
{
SqlCommand cmd = new SqlCommand("UpdateRML_byItemCode", conn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter ItemCodeParameter = new SqlParameter("@itemCode", SqlDbType.NVarChar);
ItemCodeParameter.Value = (itemCode);
cmd.Parameters.Add(ItemCodeParameter);
SqlParameter NewRMLParamter = new SqlParameter("@RML", SqlDbType.Int);
NewRMLParamter.Value = (newRML);
cmd.Parameters.Add(NewRMLParamter);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
如您所见,它通过采用两个参数并将它们传递给数据库中的存储过程进行更新来工作。不幸的是,当我按下GridView的“更新”按钮时(单击“编辑”后),我得到了这个错误。
ObjectDataSource 'ObjectDataSource1' could not find a non-generic method
'UpdateRML' that has parameters: p, itemcode, newRML, itemname, RML, Buyer, Vendor,
AvgCost, FWAC, MSRP, SalePrice, Profit_Ave, Profit_MSRP, onHand, isCommited, onOrder, ATS,
AOH, Vintage, Producer, Country, Region, Appellation, CRU, Size, RtrakDept, str.
几乎是说我需要包括GridView的所有字段,我想这并不奇怪,因为我确实在msdn上阅读了这篇文章,上面说了这样的话,但是令人沮丧的是,该方法需要在需要时使用所有这些参数除了项目代码和新数据外,我什么都没有使用。
那么解决这个问题的最佳方法是什么?我是否使它比应有的复杂?我是否应该使用带有可笑签名的此方法?如果您需要更多信息,请与我们联系!谢谢你。
万一有人发现这个问题并对答案感兴趣:如果我AutoGenerateColumns
对GridView所做的一切都设为false,请asp:BoundField
改用它。我将ReadOnly
每个BoundField的属性都设置为“ False”,除了我希望能够进行编辑的属性之外,还有bam!现在,该UpdateRML()
方法仅需要一个参数:RML。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句