locked
Why Can't I use both filterExpression and @Parameter at same time? RRS feed

  • Question

  • User1216627406 posted

    Greetings Experts,

    I have this:

       <asp:TemplateField HeaderText="">
         <ItemTemplate>
          <asp:TextBox ID="trainingId" runat="server" Text='<%# Bind("trainingId") %>' style="display:none" ></asp:TextBox>
           </ItemTemplate>
      </asp:TemplateField>

    Then this query:

                 SelectCommand="select tl.trainingid,l.locationid,c.CourseId,i.instructorId,CourseName,i.instructorname, 
           dbo.fnFormatDate(t.trainingDates, 'MON/DD/YYYY') trainingDates,t.trainingTime,CourseDescription 
           from tblCourses c
           inner join tblLocations l on c.locationid = l.locationid
           inner join tblTrainingDates t on c.dateId = t.dateId
           inner join tblCourseInstructor ci on c.courseid=ci.courseid
           inner join tblInstructors i on ci.instructorid =  i.instructorId
           inner join tblTrainings tl on ci.courseId = tl.courseId
           and YEAR(t.trainingDates) = YEAR(getDate()) and tl.trainingId = @trainingId"
           FilterExpression="LocationId = '{0}'" >

    Finally, the parameters declaration section:

                <SelectParameters>
                <asp:Parameter Type="Int32" Name="trainingId"/>
                </SelectParameters>

    When I run the code, I get no records but no records get displayed.

    If however, I run the code in SQL Server Management Studio, and replace @TrainingId with hardcoded value, I get results.

    Any ideas how to make it work?

    The idea of what we are trying to do is you select a location and results based on that location are displayed.

    It is not working for me.

    Your assistance is greatly appreciated.

    Thursday, September 18, 2014 4:15 PM

All replies

  • User343834643 posted

    Hi simflex,

    Suppose the parameter named "@trainingId" is invalid.

    If you debug the code, what does "@trainingId" look like?

    Regards,

    George.

    Friday, September 19, 2014 5:38 AM