I have a C# 2010 application that uses Crystal Reports for VS 2010. My report's purpose is to show where a person should be each day of one or more weeks. The format is this:
Please note that it is displayed in pairs, rather than a table with a general header.
It uses a DataSet that contains two DataTables, one for the header dates and one for the location.
The problem is that if I have n items in each DataTable, the report displays n^2 pairs of header / location instead of just n. The pattern is similar to a Cartesian product of the two tables.
I think it might have something to do with the linking part in the report's Database Expert but I couldn't manage to fix it. It contains no links right now.
The DataSet I use looks like this:
Why do you need a table for the headers? What are you trying to accomplish?
Why not add a date (StartOfWeek) to the WeekTable that represents the starting date of the week? If you have that date, each column header would be a formula field that calculates the day based on the StartOfWeek field. So much easier and it eliminates the Cartesian product that you are experiencing.
** edit **
There would be 7 header formulae (one for each day):
//{#Sunday}
DateAdd("d", 0, {WeekTable.StartOfWeek})
...
//{#Saturday}
DateAdd("d", 7, {WeekTable.StartOfWeek})
Add each field to the Page Header section and format as desired (they are Date values).
You need to link the tables to only get n rows.
Ideally:
Add a unique ID column to the Headers table. Make it the one primary key, and an auto-incrementing identity.
Add a HeaderID column to the WeekTable table, and make it a foreign key to the Headers table on the ID column.
The Headers table should now only include one row for each week, so if you have four employees they will all have the same HeaderID for a given week.
You may need to explain a little further what your "header dates" are. But from what you're saying they are not linked to the main data, in which case i would probably use a subreport in the header.
Related
I was wondering. If you have 50 sheets in 1 file and you have little tables in different sheets with values like 'column 1' and 'column 2'. Is it possible to look up these sheets by these values? I would add the tables to a list and then search for the values in those tables to get them out and put them in another file.
I got the datasheet part and all that, but i'm wondering how I can filter just the tables I need, then the colums I need in those tables and then loop those colums to find the values I need.
I've edited this post to get a better picture.
table
I need the values under the field that contain values 'column1', 'column2' and 'column3'
This multiple times, but you don't know in what sheet and how many times or on what row they are. So i want to find those tables and get the data.
I don't need code for the dataset. This I allready figured out. I have the dataset, I just can't figure out the filtering.
This past week I was tasked with moving a PHP based database to a new SQL database. There are a handful of requirements, but one of those was using ASP.Net MVC to connect to the SQL database...and I have never used ASP.Net or MVC.
I have successfully moved the database to SQL and have the foundation of the ASP site set up (after spending many hours pouring through tutorials). The issue I am having now is that one of the pages is meant to display a handful of fields (User_Name, Work_Date, Work_Description, Work_Location, etc) but the only way of grabbing all of those fields is by combining two of the tables. Furthermore, I am required to allow the user to search the combined table for any matching rows between a user inputted date range.
I have tried having a basic table set up that displays the correct fields and have implemented a search bar...but that only allows me to search by a single date, not a range. I have also tried to use GridView with its Query Builder feature to grab the data fields I needed (which worked really well), but I can't figure out how to attach textboxes/buttons to the newly made GridView. Using a single table with GridView works perfectly and using textboxes/buttons is very intuitive. I just can't seem to make the same connection with a joined view.
So I suppose my question is this: what is the best way for me to combine these two tables while also still having the ability to perform searches on the displayed data? If I could build this database from scratch I would have just made a table with the relevant data attached to it, but because this is derived from a previously made database it has 12+ years of information that I need to dump into it.
Any help would be greatly appreciated. I am kind of dead in the water here. My inexperience with these systems is getting the better of me. I could post the code that I have, but I am mainly interested in my options and then I can do the research on my own.
Thanks!
It's difficult to offer definitive answers to your questions due to the need for guesswork.
But here are some hints.
You can say WHERE datestamp >= '2017-01-01' AND datestamp < '2018-01-01' to filter all the rows in calendar year 2017. Many variations on this sort of date range filter are available.
Your first table probably has some kind of ID number on each row. Let's call it first.first_id. Your second table probably has its own id, let's call it second.second_id. And, it probably has another id that identifies a row in your first table, let's call it second.first_id. That second.first_id is called a foreign key in the second table to the first table. There can be any number of rows in your second table corresponding to your first table via this foreign key.
If this is the case you can do something like this:
SELECT first.datestamp, first.val1, first.val2, second.val1, second.val2
FROM first
JOIN second ON first.first_id = second.first_id
WHERE first.datestamp >= '2018-06-01' AND first.datestamp < '2018-07-01'
AND (first.val1 = 'some search term' OR second.val1 = 'some search term')
ORDER BY first.datestamp
This makes a virtual table by joining together your two physical tables (FROM...JOIN...).
Then it filters the rows you want from that virtual table (FROM ...).
Then it puts them in the order you want (ORDER BY...).
Finally, it chooses the columns from the virtual table you want in your result set (SELECT ...).
SQL database servers (MySQL, SQL Server, postgreSQL, Oracle and the rest) are very smart about doing this sort of thing efficiently.
I ask for advice what would you suggest to display 2 unrelated tables in a single report (if needed with subreport), the first one with groupings and the second one "flat"?
Details:
I am developing a report with C# 4 and Crystal Reports for Visual studio.
Data comes from a Stored procedure in Sql Server 2005, that returns 2 tables.
I pass the data to the report with the .SetDataSource(Dataset) method and I checked that data in the dataset is correct.
I need to display the data from the first table in a quite complex form with different sections. This part works.
At the end of the report I need to print the data from the second table (no grouping, just a "flat" print). To do this I added a subreport.
The tables are not related. I added a Dummy field on them with the same value and used it to mimic a relation in the database expert; I configured the subreport link, based on the dummy field.
I have 2 problems.
The data in the main report is cross joined with the second table (I could expect that since they are related with a constant field)
The subreport is always empty (I checked several times that its table in datasource contains correct data).
I tried different configurations of link and tried to place the subreport in different sections (It should be in the report footer).
I set a border around the subreport: the border is printed but inside it is empty.
I also setup a formula to count the records of both tables and put the count in the report: the count is > 0 for both.
Your approach looks wrong.... At first if both are not releated I don't see any use in creating a dummy field and linking tables which will always provide cross join. Any way as per your descrition table 1 data is saperately displayed and table 2 data is saperately displayed
As per your description in main report you need data from table 1 and in footer you need data from table 2.
Try this approach:
Don't link tables
take table 1 in main report and show the required display.
Take sub report and in that take only table 2 and display in footer and make sure don't link main report and sub report nor link two tables.
Ideally speaking, without linked table not used in crystal report as reporting tools used to display the relevant data based on our criteria and display 2 different set of data without link does not mean as a report as well as tough to integrate in crystal report.
Tough to integrate means at any point you have to link the table either via union in sqlserver or at crystal report side, other wise it display as Cartesian.
As per my thoughts you can do it by some approach.
Approach 1 : You can get the data by union or unionAll with set of columns and filter the data where table's column does not have null value ie.
http://www.maximumimpactsolutions.co.uk/blog/comments.asp?bd=118
Table1col1 Table1col2 Table1col3 Table2Col1 Table2Col2 Table2Col3
value value value null null null --table1data
null null null value value value --table2data
Approach 2 : Second is sub-report, but still need the linked as you already done. But there is proper rule to be set (this is very very tedious job).
Approach 3 : Generate 2 report at c# side and merge into one PDF, then export it.
check this links.
Reporting on multiple tables independently in Crystal Reports 11
http://www.tek-tips.com/viewthread.cfm?qid=241195
http://www.crystalreportsbook.com/Forum/forum_posts.asp?TID=4756
http://www.codeproject.com/Questions/348959/Crystal-reports-for-multiple-tables
I'm a personal trainer and I have some programming background but I don't know much about database.. I'm trying to create a program where I can store my clients personal information and especially if they have any health problems and medicines they use so that in case something happens I can quickly find the information needed so what I'm using
Xampp, and C# ( open to suggestions if I will be more successful with a different language program)
what I want is to create three tables;
1-personal_information (id(primary key) ,first_name,second_name,date of birth, 'and some other information)
2-health_information ( disease, medicines)
3-size ( kg, and sizes of the body parts like chest, biceps, triceps etc.. and date )
but one client may have more than one disease and may use more than one medicine per a disease) and
also I want to measure my clients once in 2 months and add the new sizes without losing the previous values
so I need an array of health_information and size per id but how do I do that in mysql? I'm sure that it's something very easy but just can't figure it out
thanks in advance :)
In your second table you'll want a column called personal_information_id which will correspond to a row in the personal_information table. When you want to retrieve data for specific person execute a query similar to Select * from health_information where personal_information_id = 12345. This will return all the rows in the second table that are related to patient 12345.
Obviously you'll want to do something similar for your size table.
I am wondering which method is the best way to store a list of integers in a sql column.
.....i.e. "1,2,3,4,6,7"
EDIT: These values represent other IDs in SQL tables. The row would look like
[1] [2]
id, listOfOtherIDs
The choices I have researched so far are:
A varchar of separated value that are "explode-able" i.e. by commas or tabs
An XML containing all the values individually
Using individual rows for each value.
Which method is the best method to use?
Thanks,
Ian
A single element of a record can only refer to one value; it's a basic database design principle.
You will have to change the database's design: use a single row for each value.
You might want to read up on normalization.
As is shown here in the description of the first normal form:
First normal form states that at every row and column intersection in the table there, exists a single value, and never a list of values. For example, you cannot have a field named Price in which you place more than one Price. If you think of each intersection of rows and columns as a cell, each cell can hold only one value.
While Jeroen's answer is valid for "multi-valued" attributes, there are genuine situations where multiple comma-separated values may actually be representing one large value. Things like path data (on a map), integer sequence, list of prime factors and many more could well be stored in a comma-separated varchar. I think it is better to explain what exactly are you storing and how do you need to retrieve and use that value.
EDIT:
Looking at your edit, if by IDs you mean PK of another table, then this sounds like a genuine M-N relation between this table and the one whose IDs you're storing. This stuff should really be stored in a separate gerund, which BTW is a table that would have the PK of each of these tables as FKs, thus linking the related rows of both tables. So Jeroen's answer very well suits your situation.