Solved

Must declare the Variable in ASP.NET

Posted on 2007-03-29
3
373 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

739 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