[ad_1]
When printing the receipt through the reportviewer memory leakage is arising. Even though I have tried other solutions mentioned non of it didn't give me any positive outcome. I have run the garbage collector but still did not get any outcome properly. Please give me a proper solution to sort out the matter.
私が試したこと:
static string myconn = ConfigurationManager.ConnectionStrings["connstrng"].ConnectionString; SqlConnection conn = new SqlConnection(myconn); readonly SalesF sf; public RecieptForm(SalesF frm) { InitializeComponent(); this.sf = frm; } private void RecieptForm_Load(object sender, EventArgs e) { this.reportViewer1.RefreshReport(); } public void LoadReceipt(string cashTendered, string cashBalance) { ReportDataSource receiptds; try { this.reportViewer1.LocalReport.ReportPath = Application.StartupPath + @"\Reports\CashPaymentReciept.rdlc"; this.reportViewer1.LocalReport.DataSources.Clear(); DataSet1 dc = new DataSet1(); SqlDataAdapter sda = new SqlDataAdapter(); string query = "select c.id,c.transno,c.productid,c.price,c.quantity,c.total,c.transactiondate,p.description from tbl_cart as c inner join product as p on p.productID=c.productid where transno like '" + sf.lblInvoiceNumber.Text + "'"; conn.Open(); sda.SelectCommand = new SqlCommand(query, conn); sda.Fill(dc.Tables["dtSold"]); sda.Dispose(); dc.Dispose(); ReportParameter cartTotal = new ReportParameter("cartTotal", sf.lblAmount.Text); ReportParameter cashTend = new ReportParameter("cashTendered", cashTendered); ReportParameter cashBal = new ReportParameter("cashBalance", cashBalance); ReportParameter storeName = new ReportParameter("storeName", store.ToUpper()); ReportParameter cashier = new ReportParameter("cashier", "Cashier: " + sf.lblName.Text); reportViewer1.LocalReport.SetParameters(cartTotal); reportViewer1.LocalReport.SetParameters(cashTend); reportViewer1.LocalReport.SetParameters(cashBal); reportViewer1.LocalReport.SetParameters(storeName); reportViewer1.LocalReport.SetParameters(cashier); receiptds = new ReportDataSource("DataSet1", dc.Tables["dtSold"]); reportViewer1.LocalReport.DataSources.Add(receiptds); reportViewer1.LocalReport.PrintToPrinter(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { sf.Refresh(); reportViewer1.Dispose(); GC.SuppressFinalize(reportViewer1); conn.Close(); conn.Dispose(); } }
解決策 1
string query = "select c.id,c.transno,c.productid,c.price,c.quantity,c.total,c.transactiondate,p.description from tbl_cart as c inner join product as p on p.productID=c.productid where transno like '" + sf.lblInvoiceNumber.Text + "'",CON; ADD YOUR CONNECTION AND ("DataSet1", dc.Tables["dtSold"]); DTSOLD MUST BE THE SAME NAME OF DATASET TABLE
[ad_2]
コメント