Solved

Must declare the Variable in ASP.NET

Posted on 2007-03-29
3
370 Views
Last Modified: 2012-08-13
Just a simple Application.  One GridView viewing a table information.  One DetailView viewing details when user clicks on a record on the GridView, and I am getting an error "Must Declare the variable @AffiliateID".  Please HELP!!!.

<table cellpadding=0 cellspacing=0 align="center" valign="middle" width="100%" height="93%">
    <tr>
        <td align="left" valign="top">
            <asp:GridView ID="UnapprovedAccountGrid" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                CellPadding="4" DataKeyNames="AffiliateID" DataSourceID="UnApproved_DS" ForeColor="#333333"
                GridLines="None" Width="100%" AllowSorting="True"  >
                <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                <Columns>
                    <asp:CommandField ShowSelectButton="True" SelectText="Details"/>
                    <asp:BoundField DataField="AffiliateCode" HeaderText="Affiliate Code" ReadOnly="True"
                        SortExpression="AffiliateCode" />
                    <asp:BoundField DataField="FirstName" HeaderText="First Name" SortExpression="FirstName" />
                    <asp:BoundField DataField="LastName" HeaderText="Last Name" SortExpression="LastName" />
                    <asp:BoundField DataField="Username" HeaderText="Username" SortExpression="Username" />
                    <asp:BoundField DataField="EmailAddress" HeaderText="Email Address" SortExpression="EmailAddress" />
                    <asp:BoundField DataField="SignupDate" HeaderText="Signup Date" SortExpression="SignupDate" />
                    <asp:BoundField DataField="SignupIP" HeaderText="Signup IP" SortExpression="SignupIP" />
                    <asp:BoundField DataField="ADTitle" HeaderText="AD Title" SortExpression="ADTitle" />
                    <asp:BoundField DataField="Active" HeaderText="Active" SortExpression="Active" />
                </Columns>
                <RowStyle BackColor="#EFF3FB" />
                <EditRowStyle BackColor="#2461BF" />
                <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                <HeaderStyle BackColor="#507CD1" CssClass="HeaderStyle" Font-Bold="True" ForeColor="White" />
                <AlternatingRowStyle BackColor="White" />
            </asp:GridView>
            <asp:SqlDataSource ID="UnApproved_DS" runat="server" ConnectionString="<%$ ConnectionStrings:Seamless_MainWebConnection %>"
                ProviderName="<%$ ConnectionStrings:Seamless_MainWebConnection.ProviderName %>"
                SelectCommand="SELECT af.AffiliateID,af.AffiliateCode, af.FirstName, af.LastName,
                af.Username, af.EmailAddress, af.SignupDate, af.SignupIP,
                pm.ADTitle, af.Active FROM Affiliate af INNER JOIN Promotion
                pm ON af.PromotionID = pm.PromotionID ORDER BY af.SignupDate DESC">
            </asp:SqlDataSource>
        </td>
    </tr>
    <tr>
        <td>
            <asp:DetailsView ID="UnApprovedAccountDetails" runat="server" AutoGenerateRows="False" CellPadding="4"
                DataSourceID="Unapproved" ForeColor="#333333" GridLines="None" Height="50px"
                Width="268px">
                <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                <CommandRowStyle BackColor="#D1DDF1" Font-Bold="True" />
                <EditRowStyle BackColor="#2461BF" />
                <RowStyle BackColor="#EFF3FB" />
                <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                <Fields>
                    <asp:BoundField DataField="AffiliateCode" HeaderText="Affiliate Code" ReadOnly="True"
                        SortExpression="AffiliateCode" />
                    <asp:BoundField DataField="FirstName" HeaderText="First Name" SortExpression="FirstName" />
                    <asp:BoundField DataField="LastName" HeaderText="Last Name" SortExpression="LastName" />
                    <asp:BoundField DataField="Username" HeaderText="Username" SortExpression="Username" />
                    <asp:BoundField DataField="Password" HeaderText="Password" SortExpression="Password" />
                    <asp:BoundField DataField="EmailAddress" HeaderText="Email Address" SortExpression="EmailAddress" />
                    <asp:BoundField DataField="SignupDate" HeaderText="Signup Date" ReadOnly="True" SortExpression="SignupDate" />
                    <asp:BoundField DataField="SignupIP" HeaderText="Signup IP" ReadOnly="True" SortExpression="SignupIP" />
                    <asp:BoundField DataField="PromotionID" HeaderText="Promotion ID" SortExpression="PromotionID" />
                    <asp:BoundField DataField="Points" HeaderText="Points" ReadOnly="True" SortExpression="Points" />
                    <asp:BoundField DataField="Active" HeaderText="Active" SortExpression="Active" />
                    <asp:BoundField DataField="ActivatedAdminUser" HeaderText="Activated Admin User"
                        ReadOnly="True" SortExpression="ActivatedAdminUser" />
                    <asp:BoundField DataField="Notes" HeaderText="Notes" SortExpression="Notes" />
                    <asp:CommandField ButtonType="Button" ControlStyle-CssClass="btn" DeleteText="Delete Account" EditText="Edit Affiliate Account"
                        ShowDeleteButton="True" ShowEditButton="True" />
                </Fields>
                <FieldHeaderStyle BackColor="#DEE8F5" Font-Bold="True" />
                <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                <AlternatingRowStyle BackColor="White" />
            </asp:DetailsView>
            <asp:SqlDataSource ID="Unapproved" runat="server" ConnectionString="<%$ ConnectionStrings:Seamless_MainWebConnection %>"
                ProviderName="<%$ ConnectionStrings:Seamless_MainWebConnection.ProviderName %>"
                OldValuesParameterFormatString="original_{0}"
                SelectCommand=" SELECT [AffiliateID],[AffiliateCode], [FirstName], [LastName],
                [Username], [Password], [EmailAddress], [SignupDate], [SignupIP],
                [PromotionID], [Points], [Active], [ActivatedAdminUser], [Notes] FROM
                [Affiliate] WHERE ([AffiliateID] = @AffiliateID)">
                <SelectParameters>
                    <asp:ControlParameter ControlID="UnapprovedAccountGrid" Name="AffiliateID"
                                PropertyName="SelectedIndex" Type="int32" />
                </SelectParameters>
            </asp:SqlDataSource>
           
        </td>
    </tr>
</table>
0
Comment
Question by:ResortCompanies
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
rboyd56 earned 500 total points
ID: 18820922
This variable, @AffiliateID, is being passed to the last select statement:

SELECT [AffiliateID],[AffiliateCode], [FirstName], [LastName],
                [Username], [Password], [EmailAddress], [SignupDate], [SignupIP],
                [PromotionID], [Points], [Active], [ActivatedAdminUser], [Notes] FROM
                [Affiliate] WHERE ([AffiliateID] = @AffiliateID)

Where is it being declared and assigned a value?
0
 

Author Comment

by:ResortCompanies
ID: 18820931
As far as I know:

<SelectParameters>
                    <asp:ControlParameter ControlID="UnapprovedAccountGrid" Name="AffiliateID"
                                PropertyName="SelectedIndex" Type="int32" />
                </SelectParameters>

Unless I am suppose to declare somewhere else?
0
 

Author Comment

by:ResortCompanies
ID: 18821059
I have found the answer myself.  SQL statement should be "WHERE AffiliateID = ?" rather then " = @AffiliateID"
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now