Write a custom query in Crystal Report by visual studio c#

此生再无相见时 提交于 2021-01-28 11:28:41

问题


I am new with Crystal report for c# I want to create a Crystal report that takes values from 3 MySQL tables but I want to write my custom query because when I select tables in visual studio it shows a query that doesn't meet what I expected. I tested query on localhost phpMyAdmin and it worked.

note 1: I am using visual studio 2019 and installed Crystal report SP26 note 2: when visual studio wrote the query it added "1" to the table name like boq_table make it boq_table1.

code below represents what query I want to execute:

SELECT
    ubc.boq_table.itemNum,
    ubc.boq_table.descriptionOfWork,
    ubc.boq_table.unit,
    ubc.boq_table.contractualQuantity,
    ubc.boq_table.priceNum,
    ubc.summary.executedQuantLastSummary,
    ubc.summary.priceLastWorks,
    ubc.summary.executedQuantBetw2Sum,
    ubc.submittal.priceCurrentWorks
FROM
    ubc.boq_table
LEFT OUTER JOIN ubc.summary ON
    ubc.boq_table.itemNum = ubc.summary.itemNum
LEFT OUTER JOIN ubc.submittal ON
    ubc.boq_table.itemNum = ubc.submittal.itemNum
WHERE
    ubc.boq_table.projectName ='proj'
UNION
SELECT
    ubc.boq_table.itemNum,
    ubc.boq_table.descriptionOfWork, 
    ubc.boq_table.unit, 
    ubc.boq_table.contractualQuantity, 
    ubc.boq_table.priceNum, 
    ubc.summary.executedQuantLastSummary, 
    ubc.summary.priceLastWorks, 
    ubc.summary.executedQuantBetw2Sum, 
    ubc.submittal.priceCurrentWorks 
FROM
    ubc.summary
LEFT OUTER JOIN ubc.boq_table ON 
    ubc.summary.itemNum = ubc.boq_table.itemNum 
LEFT OUTER JOIN ubc.submittal ON 
    ubc.summary.itemNum = ubc.submittal.itemNum 
WHERE 
    ubc.summary.projectName = 'proj'  
UNION
SELECT
    ubc.boq_table.itemNum,
    ubc.boq_table.descriptionOfWork,
    ubc.boq_table.unit,
    ubc.boq_table.contractualQuantity,
    ubc.boq_table.priceNum,
    ubc.summary.executedQuantLastSummary, 
    ubc.summary.priceLastWorks, 
    ubc.summary.executedQuantBetw2Sum, 
    ubc.submittal.priceCurrentWorks 
FROM
    ubc.submittal 
LEFT OUTER JOIN ubc.boq_table ON 
    ubc.submittal.itemNum = ubc.boq_table.itemNum 
LEFT OUTER JOIN ubc.summary ON 
    ubc.submittal.itemNum = ubc.summary.itemNum 
WHERE 
    ubc.submittal.projectName = 'proj' 
ORDER BY 
    itemNum;

and this code was written by the visual studio after I selected tables

 SELECT boq_table1.itemNum, boq_table1.descriptionOfWork, boq_table1.unit, boq_table1.contractualQuantity, boq_table1.priceNum, submittal1.priceCurrentWorks, summary1.executedQuantLastSummary, summary1.executedQuantBetw2Sum, summary1.priceLastWorks
 FROM   (ubc.boq_table boq_table1 INNER JOIN ubc.submittal submittal1 ON boq_table1.ID=submittal1.ID) INNER JOIN ubc.summary summary1 ON boq_table1.ID=summary1.ID
 ORDER BY boq_table1.itemNum

the last code read-only I can't edit


回答1:


You can do 2 things if you want to get data to crystal reprots, you look again in the database selector, there is an option for adding a command or use the connector and a datareader to build a dataset that you can use.

The first is ok, if you don't need to compute the data heavily.



来源:https://stackoverflow.com/questions/60015411/write-a-custom-query-in-crystal-report-by-visual-studio-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!