Solved

Print form for each row in dataset

Posted on 2009-07-10
11
654 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
  • 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

776 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