Solved

Must declare the Variable in ASP.NET

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

832 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