Connecting Tech Pros Worldwide Help | Site Map

How to access parameters of SqlDataSource

Kees de Winter
Guest
 
Posts: n/a
#1: Mar 29 '06
Hi,

I am trying to set a parameter in the SELECT statement of a SqlDataSource,
in the Page_Load event where the intended value for the parameter is
calculated. But how can I set the parameter to a certain value? If the value
comes from a control, form, querystring etc. then it's easily done
declaratively. But how to do it in code.

Have tried for hours. I will be grateful for all help!
--
Kees de Winter


clickon
Guest
 
Posts: n/a
#2: Mar 29 '06

re: How to access parameters of SqlDataSource


You could do it all programatically, set the SQLDataSource.SelectCommand
property and use the SQLDataSource.SelectParameter.Add() method to add the
parameter. Alternativley you could use the SQLDataSource.FilterExpression
and the SQLDataSource.FilterParameters properties to filter the data after
the fact.

"Kees de Winter" wrote:
[color=blue]
> Hi,
>
> I am trying to set a parameter in the SELECT statement of a SqlDataSource,
> in the Page_Load event where the intended value for the parameter is
> calculated. But how can I set the parameter to a certain value? If the value
> comes from a control, form, querystring etc. then it's easily done
> declaratively. But how to do it in code.
>
> Have tried for hours. I will be grateful for all help!
> --
> Kees de Winter
>
>
>[/color]
Flinky Wisty Pomm
Guest
 
Posts: n/a
#3: Mar 29 '06

re: How to access parameters of SqlDataSource


If you want to provide a default value for your parameter, and the
param is defined in the aspx file, just do.

protected void Page_Load(object sender, EventArgs e)
{
// do page load stuff
SetQueryDefaults();
}

private void SetQueryDefaults()
{
MySqlDataSource.SelectParameters["ParameterName"].DefaultValue =
MyValue.ToString()
}

Kees de Winter
Guest
 
Posts: n/a
#4: Mar 29 '06

re: How to access parameters of SqlDataSource


That was it! Thanks!!

--
Kees de Winter


"clickon" <clickon@discussions.microsoft.com> wrote in message
news:C7AACC26-9915-41EB-96E6-6B3FA9595EBA@microsoft.com...[color=blue]
> You could do it all programatically, set the SQLDataSource.SelectCommand
> property and use the SQLDataSource.SelectParameter.Add() method to add the
> parameter. Alternativley you could use the[/color]
SQLDataSource.FilterExpression[color=blue]
> and the SQLDataSource.FilterParameters properties to filter the data after
> the fact.
>
> "Kees de Winter" wrote:
>[color=green]
> > Hi,
> >
> > I am trying to set a parameter in the SELECT statement of a[/color][/color]
SqlDataSource,[color=blue][color=green]
> > in the Page_Load event where the intended value for the parameter is
> > calculated. But how can I set the parameter to a certain value? If the[/color][/color]
value[color=blue][color=green]
> > comes from a control, form, querystring etc. then it's easily done
> > declaratively. But how to do it in code.
> >
> > Have tried for hours. I will be grateful for all help!
> > --
> > Kees de Winter
> >
> >
> >[/color][/color]


Closed Thread