ObjectDataSource Parameter Passing

G

Guest

What is the best way to pass a parameter to an ObjectDataSource.
I am able to add a new parameter to the SelectParameters, but I would like
to just assign a value to an existing parmeter at runtime.

Currently I am just adding the parameter at runtime and setting the value:
ObjectDataSource1.SelectParameters.Add("searchCCN", "")

I would like to accomplish the following:
ObjectDataSource1.SelectParameters.("LastName") = "Doe"

The code above does not work. There is no parameter.value, only
parameter.DefaultValue. Is there a better way to set an existing parameter
value in an ObjectDataSource?

Thanks,
 
G

Guest

The DefaultValue is the correct way to set such parameters at run-time.
(There is no databound value to replace it)
 
G

Guest

Thanks for the reply. I have a follow-up question:

Should I use the Default Value or add the parameter for best practice?

1) ObjectDataSource1.SelectParameters("LastNam").DefaultValue="Doe"

2) ObjectDataSource1.SelectParameters.Add("LastName", "Doe")
 
G

Guest

I prefer to specify the parameter type to ensure type-casting is done
correctly particularly when the value might be affected by the Culture
setting of the server running the application. e.g.

ObjectDataSource1.SelectParameters.Add(New
WebControls.Parameter("OrderDate", TypeCode.DateTime, Now.ToString()))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top