Change SqlDataSource Parameter

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
 
G

Guest

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
 
T

tshad

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
 
G

Guest

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
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top