How do I set up ObjectDataSource select parameters at runtime

前端 未结 2 1422
长发绾君心
长发绾君心 2020-12-18 19:05

I\'m trying to add parameters to an objectDataSource at runtime like this:

        Parameter objCustomerParameter = new Parameter(\"CustomerID\", DbType.Stri         


        
2条回答
  •  无人及你
    2020-12-18 19:29

    Add them to the event for the operation you are trying to use. For example, if these parameters are part of the SELECT command then add them to the Selecting event, if they need to go with the UPDATE command then add them on the Updating event.

    The ObjectDataSource raises an event before it performs each operation, that's when you can insert parameters (or validate/alter existing parameters).

    Also, don't try and modify the parameters collection of the ODS itself. You want to add your parameters to the ObjectDataSourceSelectingEventArgs that is passed to the event handler.

    Something like:

    e.InputParameters["CustomerID"] = customerId;
    e.InputParameters["database"] = dbName;
    

提交回复
热议问题