?
Solved

Print form for each row in dataset

Posted on 2009-07-10
11
Medium Priority
?
668 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 2000 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

765 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