Solved

Print form for each row in dataset

Posted on 2009-07-10
11
648 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now