Solved

Print form for each row in dataset

Posted on 2009-07-10
11
663 Views
Last Modified: 2012-05-07
Hello, here is a technical difficulty for your expertise. I'm using VB.net, Visual Studio 2005, and SQL Server 2005. (Sadly, I am not using Crystal Reports; maybe sometime. My version of Visual Studio was a freebie and did not include Crystal Reports)

I cannot figure out how to print a report for each row in the dataset.

I have a Info_Database with two tables that contains all the information that I need for my report. Each record in the Company_Table contains information on one company. The Employee_Table contains all the employee information. A Left Outer Join returns a dataset containing all the company and employee information I need (W2_Dataset)

I have a form with  a reportViewer which references a W2_Report. I cannot use a table, matrix, or list control. Instead I am using a free-form approach which allows me to use lines and textboxes to make the form look the way I need it.

I am trying to use one query to pull data off the server, then step through the dataset, one record at a time. With each record, I need to print the W2_Report, then step to the next record, etc.

How do I set up the report textboxes: i.e. what expression do i use in the textbox?

What vb code do i need to step through the dataset? Do I need to create a separate dataset with just one record for this; how would I do this?

Thanks for your consideration
0
Comment
Question by:TadSter
[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
  • 7
  • 4
11 Comments
 
LVL 27

Expert Comment

by:VBRocks
ID: 24825936
0
 
LVL 2

Author Comment

by:TadSter
ID: 24826003
Thanks for the great link. I have been through all that already. It does not address how to print one specific row of the dataset.

Is there more...
0
 
LVL 27

Expert Comment

by:VBRocks
ID: 24826224
Have you tried using a DataView and filtering it for just that record?

Have you tried cloning the DataSet, then copying just the record you want over, and using that as the DataSource for the report?



0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:TadSter
ID: 24826319
Cloning the dataset... I'm not sure how to do that. I assume I need to create another dataset with the same structure then at runtime fill it with one record.

That's helpful...
0
 
LVL 2

Author Comment

by:TadSter
ID: 24826508
I'm working on the Form_Load event

How do I return a dataset as a variable so I can manipulate it?

Dim dsAll As DataSet
dsAll = me.W2All_TableAdapter.AllDataTable.GetData("2008")

This doesn't work, Can you tell me why?
0
 
LVL 2

Author Comment

by:TadSter
ID: 24827084
OK, here is what I have so far. I would be grateful for additional help.

How do I copy one row of dtAll to dtOne?
Private Sub TestForm1_Load ...
 
        Dim dtAll As DataTable
        dtAll = Me.W2_TableAllTableAdapter.GetData(Main.DataYear)
 
        Dim dtOne As DataTable
        dtOne = dtAll.Clone

Open in new window

0
 
LVL 27

Expert Comment

by:VBRocks
ID: 24827138
Well, your "All" DataTable is in a DataSet (I don't know what you've called it).  But you need to use the Fill method to fill the table that is in the DataSet.

Example (let's say your DataSet is named "AllDataSet")
    Dim ds As New AllDataSet()
    Me.W2_TableAllTableAdapter.Fill(ds.All)  'Fill the "All" DataTable.

Then, set the report viewer data source to the dataset, and pass it the name of the datatable.

0
 
LVL 2

Author Comment

by:TadSter
ID: 24827253
Awesome!

Now how do I limit my second datatable to one record?  In a loop?

Private Sub TestForm1_Load ...
        Dim dsAll As New PayrollAllW2s
        Me.W2_TableAllTableAdapter.Fill(dsAll.W2_TableAll, Main.DataYear)
 
'pseudo-code loop
'I'm not sure how to implement the loop with one record each time
dim record as ???
For each record in datatable???
        ??? Dim dsOne As New PayrollOneW2
        ??? Me.W2_TableTableAdapter.Fill(dsOne.W2_Table, Main.DataYear)
 
        me.print()
 
next

Open in new window

0
 
LVL 2

Author Comment

by:TadSter
ID: 24827412
Hey I might have it here; I will need to wait till next week to really test it. If you have any critique, please go ahead.

Thanks a bunch for your help.

Private Sub TestForm1_Load ...
        Dim dsAll As New PayrollAllW2s
        Me.W2_TableAllTableAdapter.Fill(dsAll.W2_TableAll, Main.DataYear)
 
        Dim row As DataRow ' for loop
        Dim dtOne As New DataTable
        dtOne = dsAll.Tables(0).Clone
 
        For Each row In dsAll.Tables(0).Rows
            dtOne.Clear()
            dtOne.ImportRow(row)
            Me.W2_TableTableAdapter.Fill(dtOne, Main.DataYear)
 
            'print it out
        Next

Open in new window

0
 
LVL 27

Accepted Solution

by:
VBRocks earned 500 total points
ID: 24827594
Actually, you can create a new instance of the dataset, and just add the row(s) you want, or clone the dataset.

Dim ds As New PayrollAllW2s()

'Get the Default DataView of the table
Dim view As DataView = dsAll.Tables(0).DefaultView

'Filter the view to get the data you want.
'  Replace "columnName" with the name of the column you want to filter by
'  If the column you want to filter by is a Date column, enclose the value with "#"
'    example:  view.RowFilter = "columnName=#7/10/2009#"
view.RowFilter = "columnName='value'"

'Loop through each row in the view and add it to the new dataset
For Each rowView As DataRowView in view
  ds.Tables(0).Rows.LoadDataRow(rowView.row.ItemArray, True)
Next

'Now use the new DataSet as the source for your report.

Note - I didn't test this code, but just typed it right into this post.  If you have any problems with it, let me know and I'll take a look at it.
0
 
LVL 2

Author Comment

by:TadSter
ID: 24839551
Marvelous! Thank you so much for your excellent help.

Here is the code that I am using:

I may have some more issues, but I'll post separate questions for that.
    Sub doData()
        'assign variable to existing dataset instance 
        Dim dsAll As PayrollAllW2s = Me.PayrollAllW2s
 
        'fill it; limits data to current year
        Me.W2_TableAllTableAdapter.Fill(dsAll.W2_TableAll, Main.DataYear)
 
        'set up second instance of dataset
        Dim ds As New PayrollAllW2s
 
        'get the default view
        Dim view As DataView = dsAll.Tables(0).DefaultView
 
        'loop
        For Each rowView As DataRowView In view
 
            'load the data
            ds.Tables(0).Clear()
            ds.Tables(0).LoadDataRow(rowView.Row.ItemArray, True)
 
            'refresh report
            Me.ReportViewer1.RefreshReport()
 
            'verify loop
            MsgBox(ds.Tables(0).Rows(0).Item("Comp_Name") & " " & ds.Tables(0).Rows(0).Item("FirstName") & " " & ds.Tables(0).Rows(0).Item("LastName") & " " & ds.Tables(0).Rows(0).Item("Wages"))
 
            'print it out
 
        Next
    End Sub

Open in new window

0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

726 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