Solved

Must declare the Variable in ASP.NET

Posted on 2007-03-29
3
374 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

729 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