c#.netデスクトップアプリケーションのCrystalレポートのクエリに従ってデータを表示しています。問題の原因は、私がクエリを変更すると、クエリが変化していることと、そのデータを示すテンポラリテーブルのクエリにもよるが、クリスタルレポートでは、クエリの後に以前と同じデータを表示している変更する。変更後、クリスタルレポートに同じデータが表示されます
例:請求書番号1を印刷したいので、その時は大丈夫です。しかし、私はその時に請求書2を印刷したいと思っています。私はできない法案ここには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で「プレビュードキュメント」ボタンをクリックすると、ボタンのクリックイベントで私のコード"イベントが発生します。
このイベントでは、クリスタルレポートで表示したいクエリーデータに応じてこの処理を行いたいと思います。
アドバンスありがとうございました。