Author |
Message |
JohnS.
Newbie
Joined: 08 Mar 2007
Location: United States
Online Status: Offline
Posts: 18
|
Topic: Trouble with basic report Posted: 14 Mar 2007 at 1:13pm |
Hey all,
I am not sure the proper way to do this, but what i am trying to accomplish is a monthly report on all customers and there orders.
I have just finished 6 reports with master detail relationship dealing with just one customer and and list of there orders but i cannot seem to come up with all customers and there orders.
I am using SQL select statements in my Commandtext Such as this:
MyConnection = New SqlClient.SqlConnection("Data Source=SERVERName;Initial Catalog=DBName;Integrated Security=True")
MyCommand.Connection = MyConnection
MyCommand.CommandText = "Select * From Customers WHERE Customers.ID LIKE '%" + MyGuid + "%'"
MyCommand.CommandType = CommandType.Text
myDataAdapter.SelectCommand = MyCommand
myDataAdapter.Fill(myDataset, "Customers")
rpt.SetDataSource(myDataset)
CrystalReportViewer1.ReportSource = rpt
MyCommand.CommandText = "Select * From CustomersDetails WHERE CustomersDetails.SOVEntryID LIKE '%" + MySecondGuid + "%'"
MyCommand.CommandType = CommandType.Text
myDataAdapter.SelectCommand = MyCommand
myDataAdapter.Fill(myDataset, "CustomersDetails")
rpt.SetDataSource(myDataset)
But i am having no luck with creating a list. Would i have to do some type of looping to go through all customers or is there another way.
Thanks for your help, If more info is needed let me know.
JohnS.
|
IP Logged |
|
BrianBischof
Admin Group
Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
|
Posted: 14 Mar 2007 at 1:29pm |
I think your problem is that you are conceptually thinking of processing the data manually as if you were looping through the database and passing each customer to the report. Instead, get rid of the filters on the Customer GUID and just pull all the customers over. As long as you have a Group in Crystal Reports based upon Customers.ID, then it will separate all the detail records for you and associate them to the proper group.
Also, rather than using two datasets, you could use a single Command object and use the JOIN statement to pull the customer header and detail records into a single dataset. It's faster that way since SQL does the work of joining the records and all Crystal Reports has to do is group and print them.
|
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
|
IP Logged |
|
JohnS.
Newbie
Joined: 08 Mar 2007
Location: United States
Online Status: Offline
Posts: 18
|
Posted: 14 Mar 2007 at 1:46pm |
Hey Brian,
Thanks again for the quick reply. Will the Group elemenate the error i Get ( Violation of nonnull or unique key values) I tried the right outer join with a subreport of the orders inside of the main report with the customer in the detail section together.
I probably need to spend more time reading the books. I just received the two you wrote and have not read through completey, but just skimmed to get some answers i needed.
The above code was what i used to catch the Guid number for a specific customer from my form where i displayed the reportviewer from a print button.
JohnS.
Edited by JohnS. - 14 Mar 2007 at 1:48pm
|
IP Logged |
|
BrianBischof
Admin Group
Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
|
Posted: 14 Mar 2007 at 2:27pm |
Hmm.. Don't know about the error you are getting, but it sounds like a NULL value is going into a field that doesn't allow nulls. Something inside the dataset schema must not allow nulls. But I don't know why you are using datasets. I only do that for complex SQL or when I have to massage the data manually prior to passing it to the report. If you're just pulling basic data from a table then I would do it with OLE DB with a DSN-less connection and let Crystal Reports worry about opening the connection and reading the database. This is much easier unless you have a special requirement that I don't see listed here.
Re your report structure, a parent-child report is pretty simple once you've done it once. Just select the tables in Crystal Reports and link them together. Put the customer Id as the group field and put the child records in the detail section. From what I've read of your post, doing subreports is overkill right now. You only need that if you are pulling from two separate child tables.
|
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
|
IP Logged |
|
JohnS.
Newbie
Joined: 08 Mar 2007
Location: United States
Online Status: Offline
Posts: 18
|
Posted: 15 Mar 2007 at 9:16am |
Hey Brian,
Dude you are awsome!
I followed your advice and using the OLE DB connection and that works great. Verys simple to get these reports done now.
My only question. Is that the server name that i use on my design computer is different from the server name on our main computer. I use a laptop for my design work as well as a desktop. The desktop is already connected to the main server so is it best to do the design on that one or will crystal reports pick up on the server name change from my laptop to servername and the main servername.
Thanks again for the help it has moved me very far forward.
JohnS.
|
IP Logged |
|
BrianBischof
Admin Group
Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
|
Posted: 15 Mar 2007 at 11:15am |
Glad it worked! You can switch reports between different servers, but it takes code and more testing. You are better off just developing for the production server from you desktop if its not too inconvenient.
|
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
|
IP Logged |
|
JohnS.
Newbie
Joined: 08 Mar 2007
Location: United States
Online Status: Offline
Posts: 18
|
Posted: 15 Mar 2007 at 4:43pm |
Thanks again for the help.
I will probably do that for now, stick with designing the reports on the desktop PC. and maybe take some more time later to do work back and forth on the laptop to see what i can come up with.
Great Forum! It has been a big help. Hope to post some helpful tips myself sometime.
JohnS.
Edited by JohnS. - 15 Mar 2007 at 4:43pm
|
IP Logged |
|
BrianBischof
Admin Group
Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
|
Posted: 15 Mar 2007 at 5:21pm |
Switching from the dev server to production server isn't a big deal. You just need to write a few lines of code to do it (I have examples in my .NET book). It's just easier if you don't have to. Glad you like the forum! Feel free to post some tips when you can. I can always use the help.
|
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
|
IP Logged |
|
|