0

我正在使用由 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 上阅读了这篇文章,其中说了类似的话,但令人沮丧的是,该方法需要在何时获取所有这些参数除了 itemcode 和新数据,我没有使用任何东西。

那么解决这个问题的最佳方法是什么?我是否让它变得比它应该的更复杂?我应该只使用带有荒谬签名的这种方法吗?如果您需要更多信息,请与我们联系!谢谢你。

4

1 回答 1

0

万一有人发现这一点并对答案感兴趣:我必须AutoGenerateColumns将 GridView 设置为 false,然后asp:BoundField改用。我将ReadOnly每个 BoundField 的属性设置为“False”,但我希望能够编辑的属性除外,然后 bam!现在该UpdateRML()方法只需要一个参数:RML。

于 2013-07-09T19:18:33.247 回答