我試圖在Crystal Report Viewer中執行我的內部聯接查詢。查詢從SQL Server的「新查詢」部分運行時起作用。C#WinForm - 水晶報表不顯示內部聯接查詢的正確結果
SELECT TABLE1.column1,TABLE2.column1
FROM TABLE2 INNER JOIN TABLE1 ON TABLE2.Identifier=TABLE1.Identifier
WHERE DateFrom='1/1/2016' AND DateTo='1/1/2017'
但是,當我把我的代碼放入報告時,結果是不正確的比較。爲什麼從報表運行SQL時結果會有所不同?
DBConnection dbcon = new DBConnection();
cystalreportName crn = new cystalreportName();
private void Form1_Load(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = dbcon.getcon();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "..."; // the inner join query the I used.
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds, "TABLE2");
crn.SetDataSource(ds.Tables["TABLE2"]);
crystalreportviewer.ReportSource = crn;
crystalreportviewer.Refresh();
}
有你看看ds.Tables [ 「TABLE2」]的內容? – Kinetic
我在我的水晶報告數據源中包含該表。但我想知道爲什麼在我的水晶報表查看器中,它執行其中的所有數據。執行將會像在我的內部查詢定義中一樣。 –
在將它分配給Crystal Report之前,你看過ds.Tables [「TABLE2」]的內容嗎? – Kinetic