0

I am making a bill report project in window form in C#. When i click on print button ,my report viewer form can not fetch my current data from database which means that when I start application and insert values in the database then my report viewer can not fetch the latest values. But, when I close my application and re open report, then it fetch all data including my last transaction value.

How can i fetch my current values on click of my print button. I tried but it does not not work on current values.

 private void Form2_Load(object sender, EventArgs e) 
{
    cn = new SqlConnection(databaseconnection);
    da = new SqlDataAdapter("select * from Bill_Detail order by billId DESC", cn);
    DataSet ds = new DataSet(); 
    da.Fill(ds);
    int id = Convert.ToInt32(ds.Tables[0].Rows[0][0].ToString());
    this.Customer_detailTableAdapter.Fill(this.DataSet1.Customer_detail,id); 
    this.Bill_DetailTableAdapter.Fill(this.DataSet2.Bill_Detail, id);   
    this.reportViewer1.RefreshReport();
}  
Zo Has
  • 12,599
  • 22
  • 87
  • 149
user3480008
  • 11
  • 1
  • 6

2 Answers2

0
  1. Check whether 'save data in report' is enabled in report settings. Uncheck this option if this is a crystal report.
  2. The second option is to right click your report-> go to Design->Default Settings->Reporting tab and verify that 'Discard Save Data when loading reports is checked'

enter image description here

Zo Has
  • 12,599
  • 22
  • 87
  • 149
  • I am using rdlc report viewer not crystal report.Plz give me idea on report viewer. – user3480008 Mar 31 '14 at 06:50
  • @user3480008 Have you rebuild your project? Also take a look at this thread http://stackoverflow.com/questions/4587103/rdlc-report-data-doesnt-update-to-reflect-changes – Zo Has Mar 31 '14 at 08:49
  • No..i still use report viewer control. – user3480008 Mar 31 '14 at 09:24
  • @user3480008 Can you update your original question with the code you are using after update and initial load of your report? – Zo Has Mar 31 '14 at 09:27
  • private void Form2_Load(object sender, EventArgs e) {cn = new SqlConnection(databaseconnection); da = new SqlDataAdapter("select * from Bill_Detail order by billId DESC", cn); DataSet ds = new DataSet(); da.Fill(ds); int id = Convert.ToInt32(ds.Tables[0].Rows[0][0].ToString()); this.Customer_detailTableAdapter.Fill(this.DataSet1.Customer_detail,id); this.Bill_DetailTableAdapter.Fill(this.DataSet2.Bill_Detail, id); this.reportViewer1.RefreshReport(); } – user3480008 Mar 31 '14 at 09:33
  • when i click on print button that is on Form1 data is inserted in Db but billid releted data is not displayed on report viewer. – user3480008 Mar 31 '14 at 09:44
0

try this

DataView dview = new DataView();
        dview.Table = LoadReport().Tables["StudTable"];
ItemsReport myreport = new ItemsReport();
        myreport.SetDataSource(dview); 
SqlConnection myConn = new SqlConnection(_connString);
SqlDataAdapter da = new SqlDataAdapter("select * from Bill_Detail order by billId DESC", myConn);
DataSet ds = new DataSet();
da.Fill(ds, "StudTable");
return ds;
kmas
  • 6,401
  • 13
  • 40
  • 62
Nauman Khan
  • 509
  • 7
  • 20