Question

I'm working with a GridView backed by an ObjectDataSource on an ASP.net web-forms application. The GridView takes a lot of fields from the DataBase and displays them. I want to enable the editting of just a single one of these fields, but I'm already running into some problems. My update command for the ObjectDataSource looks like this:

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();

        }

As you can see, it works by taking two parameters and passing them to a stored procedure in the database to do the updating. Unfortunately I'm getting this error when I press the "Update" button the GridView (after clicking edit).

 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. 

Pretty much it's saying that I need to include ALL the fields of the GridView, which I guess wasn't surprising as I did read this article on msdn where it said something like this, but it's frustrating the method needs to take ALL those parameters when I'm not using anything but the itemcode and the new data.

So what's the best way to go about this? Am I making it more complicated than it should be? Should I just have this method with a ridiculous signature? Let me know if you need more information! Thank you.

Was it helpful?

Solution

In case anyone finds this and is interested in the answer: all I had to was set AutoGenerateColumns to false for the GridView, and use asp:BoundField instead. I set the ReadOnly property of each BoundField to "False" except for the one I wanted to to be able to edit, and bam! Now the UpdateRML() method only required one argument: RML.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top