PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
[RESOLVED] Pages always show all records not just the one queried-VBForums
Results 1 to 9 of 9

Thread: [RESOLVED] Pages always show all records not just the one queried

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2006
    Posts
    309

    Resolved [RESOLVED] Pages always show all records not just the one queried

    I am trying to print out a report based on the data entered in a text box as the parameter for the ALLWorkOrdersTableAdapter. it has listed one normal Fill,GetData() all items, and one FillBy,GetDataBy with a parameter of @WOID (which is the WorkOrder ID numberin the database MSSQL V17.19.1

    I can see the Parameter on the printout Listed IN the center of the report in BOLD for testing. But you can see the Work Order Number shown at the top is #19 the first record. I'm querring for #19.
    Shown below is the code for the Parameter being passed and calling the report to print
    Code:
    Imports Microsoft.Reporting.WinForms
    Public Class PrintWO
        Private Sub PrintWO_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            'TODO: This line of code loads data into the 'HiTechDataSet8PrintWO.AllWorkOrders' table. You can move, or remove it, as needed.
            Me.AllWorkOrdersTableAdapter.Fill(Me.HiTechDataSet8PrintWO.AllWorkOrders)
    
            'Me.ReportViewer1.RefreshReport()
        End Sub
        Private Shared Function NEWMethod()
            Dim WOID As New ReportParameter
            Return WOID
        End Function
    
        Private Sub cmdPrint_Click(sender As Object, e As EventArgs) Handles cmdPrint.Click
            '' Dim WOID As New ReportParameter
            '
            Dim WOID As ReportParameter = NEWMethod()
            WOID.Name = "WOID"
            WOID.Values.Add(txtBoxWO.Text)
    
            Try
                Me.AllWorkOrdersTableAdapter.Fill(Me.HiTechDataSet8PrintWO.AllWorkOrders)
                ReportViewer1.LocalReport.SetParameters(New ReportParameter() {WOID})
                Me.ReportViewer1.RefreshReport()
            Catch ex As Exception
                MessageBox.Show(ex.ToString)
            End Try
    
    
            WOID.Values.Add(txtBoxWO.Text)
    
            'REFRESH THE REPORT
            Me.ReportViewer1.RefreshReport()
        End Sub
    End Class
    Here is a shot of the report It has all the page record 10 thru 19
    Name:  WO lands print..jpg
Views: 84
Size:  15.3 KB

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,372

    Re: Pages always show all records not just the one queried

    You say yourself that your table adapter has a Fill method that gets all the data and a FillBy method that gets only the data that matches a specific WorkOrder ID. Which one are you calling? Clearly you are calling the first one, so clearly you are going to get all the data and not the filtered data. You have apparently added a parameter to your report but that has nothing to do with the table adapter. Unless you have configured the report to use that parameter to filter the data you give it, it's not going to do anything useful. Of course, it would be silly to retrieve all the data from the database and then have the report do the filtering when you could just retrieve the data you needed in the first place.

    Think of it this way. Let's say that you have a box full of box full of books with different coloured covers and you want to put only those with covers of a certain colour on a shelf. There are two people to do the work: one who takes the books out of the box and passes them to another person and the second person puts them on the shelf. You could have the first person just take all the books out and pass them to the second person and the second person discard those of the wrong colour and put the correct coloured ones on the shelf, or you could have the first person only take out books of the right colour and the second person just put everything they get passed on the shelf. What you're doing is akin to having the first person just pass every book to the second person while telling the second person a colour without telling them they are supposed to only put books of that colour on the shelf. You end up with every book on the shelf because you never told anyone to filter by colour.

    In short, get rid of the report parameter altogether and actually call the table adapter method that does the filtering. If you don't call that method, why on Earth did you add it in the first place?

    Also, the methods should not be named FillBy and GetDataBy. Use your head. The idea is that you name them based on what they filter by. I already addressed this in another thread. If you're filtering by WordOrder ID then the methods should be named FillByWorkOrderID and GetDataByWorkOrderID. If you add multiple queries that filter in different ways, you can then see easily which method to call based on the descriptive name.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2006
    Posts
    309

    Re: Pages always show all records not just the one queried

    I guess I slow but do not seem to be able to figure out how to do a query without asking for the particular item I want to query on. Its not a known item until you decide to ask for it. If I have a thousand Work Orders how do I reprint one without asking for it by it's ID. Am I reading you answer incorrectly? How do I do this without a Parameter?
    I believe you said I had to do a FillBy if I was doing a parameter.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2006
    Posts
    309

    Re: Pages always show all records not just the one queried

    I guess I slow but do not seem to be able to figure out how to do a query without asking for the particular item I want to query on. Its not a known item until you decide to ask for it. If I have a thousand Work Orders how do I reprint one without asking for it by it's ID. Am I reading you answer incorrectly? How do I do this without a Parameter?
    I believe you said I had to do a FillBy if I was doing a parameter.

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,372

    Re: Pages always show all records not just the one queried

    Just forget everything you think you know on this because it is all wrong. Firstly, when you create a typed DataSet, a DataTable and table adapter will be added for each table in your database. Each table adapter has a Fill method to populate an existing DataTable and a GetData method to return a new, populated DataTable. In both those cases, those methods execute the default query that gets every record from the database table. If you have a WorkOrder table then that query be effectively be:
    sql Code:
    1. SELECT * FROM WorkOrder
    If you want to be able to retrieve a subset of the data then you need to add an extra query to the table adapter. If your table has a WorkOrderId column as the primary key and you want to be able to retrieve a single record by that ID then you would add another query to your table adapter:
    sql Code:
    1. SELECT * FROM WorkOrder WHERE WorkOrderId = @WorkOrderId
    You should name the corresponding methods FillByWorkOrderId and GetDataByWorkOrderId. Those methods will have a parameter named WorkOrderId and when you call them you pass that value. The argument is passed on to the query and the data is filtered at the database, so your DataTable is only populated with data matching that filter parameter. You then pass that already-filtered data on to the report. The report then doesn't need to do any filtering because it's receiving data is already filtered.

    Yes, I did say that you needed a FillBy method (a generic name, not one you should actually use in practice) but implicit in that is that you actually call it. If you're going to call that method, you need to provide the DataTable that you want to populate AND the value you want to filter by. It's getting in there by magic.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2006
    Posts
    309

    Re: Pages always show all records not just the one queried

    I have the second query that uses the Parameter Mine is named WOID, that data has had the information passed from a text box. That part is working. when I run the query from the query builder it works show only one record as asked for. So I guess my question is how do I get the FillBy,GetDataBy (@WOID) to show its dat instead of the fill,getData() section of the AllWorOrdersTableAdapter?
    This appears to me my problem ,YES?
    You know your helping a 66 year old would be programmer?
    Thanks

  7. #7
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,372

    Re: Pages always show all records not just the one queried

    FillBy is a method. For a method to do anything, you have to call it. You are not calling that method. How many times can I say the same thing? Look at your code. You are calling Fill twice. If you want to execute FillBy then call FillBy, NOT Fill. It would probably help if you did some reading on the subject:

    https://docs.microsoft.com/en-us/vis...s?view=vs-2019

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2006
    Posts
    309

    Re: Pages always show all records not just the one queried

    thanks for your time and help. This might not be kosher but it is working and a 2:00 AM that's cool. Here is my code change i'm sure tomorrow I can clean it up some.
    Code:
      Try
                Me.AllWorkOrdersTableAdapter.FillBy(Me.HiTechDataSet8PrintWO.AllWorkOrders, txtBoxWO.Text)
                ReportViewer1.LocalReport.SetParameters(New ReportParameter() {WOID})
                Me.ReportViewer1.RefreshReport()
            Catch ex As Exception
                MessageBox.Show(ex.ToString)
            End Try
    thanks again

  9. #9
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,372

    Re: [RESOLVED] Pages always show all records not just the one queried

    That looks much better.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width