Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Print form for each row in dataset

Posted on 2009-07-10
11
Medium Priority
?
676 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
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…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

783 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