Change SqlDataSource Parameter

  • Thread starter Thread starter tshad
  • Start date Start date
T

tshad

I am trying to change the SQLDataSource parameter programatically but am
getting an error:

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$
ConnectionStrings:CSpearAndAssociatesConnectionString %>"
SelectCommand="GetQuestions" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter DefaultValue="1" Name="SurveyTestID" Type="Int32"
/>
</SelectParameters>
</asp:SqlDataSource>

I tried:

SqlDataSource1.SelectParameters["SurveyTestID"].DefaultValue =
Request("ST")

But got the error:

Property access must assign to the property or use its value.

What am I missing?

Thanks

Tom
 
I am trying to change the SQLDataSource parameter programatically but am
getting an error:

    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$
ConnectionStrings:CSpearAndAssociatesConnectionString %>"
        SelectCommand="GetQuestions" SelectCommandType="StoredProcedure">
        <SelectParameters>
            <asp:Parameter DefaultValue="1" Name="SurveyTestID" Type="Int32"
/>
        </SelectParameters>
    </asp:SqlDataSource>

I tried:

      SqlDataSource1.SelectParameters["SurveyTestID"].DefaultValue =
Request("ST")

But got the error:

    Property access must assign to the property or use its value.

What am I missing?

Thanks

Tom

Tom,

is it VB or C#? :-) If you're using VB, use parenthesis instead of
brackets, and vice versa

Hope this helps
 
Alexey said:
I am trying to change the SQLDataSource parameter programatically
but am getting an error:

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$
ConnectionStrings:CSpearAndAssociatesConnectionString %>"
SelectCommand="GetQuestions" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter DefaultValue="1" Name="SurveyTestID" Type="Int32"
/>
</SelectParameters>
</asp:SqlDataSource>

I tried:

SqlDataSource1.SelectParameters["SurveyTestID"].DefaultValue =
Request("ST")

But got the error:

Property access must assign to the property or use its value.

What am I missing?

Thanks

Tom

Tom,

is it VB or C#? :-) If you're using VB, use parenthesis instead of
brackets, and vice versa
That was it. I am doing projects in both VB.net and C# and sometimes miss
that.

BTW, why is it SqlDataSource1.SelectParameters["SurveyTestID"].DefaultValue
and not Value?

Thanks,

Tom
 
Alexey said:
I am trying to change the SQLDataSource parameter programatically
but am getting an error:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$
ConnectionStrings:CSpearAndAssociatesConnectionString %>"
SelectCommand="GetQuestions" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter DefaultValue="1" Name="SurveyTestID" Type="Int32"
/>
</SelectParameters>
</asp:SqlDataSource>
I tried:
SqlDataSource1.SelectParameters["SurveyTestID"].DefaultValue =
Request("ST")
But got the error:
Property access must assign to the property or use its value.
What am I missing?
Thanks
Tom

is it VB or C#? :-) If you're using VB, use parenthesis instead of
brackets, and vice versa

That was it.  I am doing projects in both VB.net and C# and sometimes miss
that.

BTW, why is it SqlDataSource1.SelectParameters["SurveyTestID"].DefaultValue
and not Value?

Thanks,

Tom
Hope this helps

Regarding Value. As MSDN says "A string that serves as a default value
for the Parameter when the value it is bound to cannot be resolved or
is uninitialized." In your code the value comes from SurveyTestID.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.parameter..defaultvalue.aspx
 
Back
Top