gpt4 book ai didi

c# - 更改查询后也在 Crystal 报表中显示相同的数据

转载 作者:太空宇宙 更新时间:2023-11-03 15:09:06 24 4
gpt4 key购买 nike

我在 c#.net 桌面应用程序中根据 Crystal 报表中的查询显示数据。引起问题的是,当我更改查询时,查询正在更改并且根据临时表中的查询也显示数据,但在 Crystal 报表中它没有显示新数据它显示的是查询之后的相同数据也改变。

例如:我想打印 1 号账单,这样时间就可以了。但是当我当时想打印 2 号账单时,也在 Crystal 报表中只显示 1 号账单。所以,这就是我无法打印 2 号账单的原因。

这是我在按钮点击事件中的代码

private void btn_previewdocument_Click(object sender, EventArgs e)
{
try
{
string mtmptbl = "TmpRetailInvoicePrint";
RetailInvoicePrint frm = new RetailInvoicePrint();
Cursor = Cursors.WaitCursor;
timer1.Enabled = true;

ReportDocument cryRpt = new ReportDocument();
SqlCommand MyCommand = new SqlCommand();
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(cn.ConnectionString);
ConnectionInfo crConnectionInfo = new ConnectionInfo();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();

string qryPreviewDocument = " SELECT Client.clientname as ClientName, " + System.Environment.NewLine;
qryPreviewDocument += " RetailInvoice.invoiceno as InvoiceNo, " + System.Environment.NewLine;
qryPreviewDocument += " RetailInvoice.pono as PoNO, RetailInvoice.issuedate as IssueDate, RetailInvoice.duedate as DueDate, " + System.Environment.NewLine;
qryPreviewDocument += " RetailInvoice.discount as Discount, RetailInvoice.shipping as Shipping, RetailInvoice.tax as Tax, RetailInvoice.vat as Vat, " + System.Environment.NewLine;
qryPreviewDocument += " RetailInvoice.sese as Sese, RetailInvoice.paymenttype as PaymentType, RetailInvoice.chequeno as Chequeno, RetailInvoice.totalamt as TotalAmt, " + System.Environment.NewLine;
qryPreviewDocument += " RetailInvoice.description as Description, RetailInvoice.paymentpaid as PaymentPaid, RetailInvoice.subtotal as Subtotal, " + System.Environment.NewLine;

qryPreviewDocument += " RetailInvoicePayment.productid as ProductName, RetailInvoicePayment.uom as Uom, " + System.Environment.NewLine;
qryPreviewDocument += " RetailInvoicePayment.quantity as Quantity, RetailInvoicePayment.price as Price" + System.Environment.NewLine;

qryPreviewDocument += " into " + mtmptbl + " " + System.Environment.NewLine;

qryPreviewDocument += " from tbl_retailinvoice RetailInvoice LEFT OUTER JOIN tbl_retailinvoicepayment RetailInvoicePayment " + System.Environment.NewLine;
qryPreviewDocument += " ON RetailInvoice.invoiceno = RetailInvoicePayment.invoiceno " + System.Environment.NewLine;
qryPreviewDocument += " LEFT OUTER JOIN tbl_clientdetail Client ON RetailInvoice.clientid = Client.clientid " + System.Environment.NewLine;

qryPreviewDocument += " where RetailInvoice.BranchID = " + lbl_branchid.Text + " " + System.Environment.NewLine;
qryPreviewDocument += " and RetailInvoice.YearID = " + lbl_yearid.Text + " " + System.Environment.NewLine;
qryPreviewDocument += " and RetailInvoice.invoiceno = " + txt_invoice.Text + "";


string SQL = "select upper(name) as TABLE_NAME FROM sysobjects WHERE type = 'U' and name = '" + mtmptbl + "' order by name";
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(SQL, cn);
da.Fill(dt);
if (dt.Rows.Count > 0)
{
string qrydrop = "drop table " + mtmptbl + "";
SqlCommand cmd = new SqlCommand(qrydrop, cn);
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
}

MyCommand = new SqlCommand(qryPreviewDocument, cn);
MyCommand.CommandType = CommandType.Text;
cn.Open();
MyCommand.ExecuteNonQuery();
cn.Close();

string crReportPath = Application.StartupPath.Replace("bin\\Debug", "") + "\\Print";

cryRpt.Load(crReportPath + "\\RptRetailInvoice.rpt");

builder.ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["con"];
string dbName = builder.InitialCatalog;
string dbDataSource = builder.DataSource;
string userID = builder.UserID;
string pass = builder.Password;

crConnectionInfo.ServerName = dbDataSource;
crConnectionInfo.DatabaseName = dbName;
crConnectionInfo.UserID = userID;
crConnectionInfo.Password = pass;

Tables Crtables;
Crtables = cryRpt.Database.Tables;

foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in Crtables)
{
crtableLogoninfo = CrTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crtableLogoninfo);
}

frm.crystalReportViewer1.ReportSource = cryRpt;
frm.crystalReportViewer1.RefreshReport();

Cursor = Cursors.Arrow;
frm.Show();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

因此,当任何人单击“预览文档”按钮时,“btn_previewdocument_Click”事件就会发生。

而我想在这个事件中根据要在 Crystal 报表中显示的查询数据来做。

提前致谢。

最佳答案

试试这个。在 frm.crystalReportViewer1.ReportSource = cryRpt; 之前添加 cryRpt.Refresh();

关于c# - 更改查询后也在 Crystal 报表中显示相同的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41972494/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com