Click here to Skip to main content
15,901,284 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Hi,
i am making a bill application in window form C# .i take two data set and drag and drop two tables for printing data on report view.then i create a report and bind data with these data set then after new Form and drag and drop report viewer control.when i run this application on clicking submit button current bill's data inserted into data base.and i want to print this last bill id's detail on report.![enter image description here][1]


when i click on submit button this bill no's all detail inserted into data base properly.
Code of save and print button in c#:

C#
private void button3_Click_1(object sender, EventArgs e)
       {
           this.Close();

           Form2 f2 = new Form2();
           f2.Show();

       }

after clicking save and print below form open.![enter image description here][2].
Code of Button click :

C#
private void button1_Click(object sender, EventArgs e)
         {
	da = new SqlDataAdapter("select billId 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());
             textBox1.Text = id.ToString();   
           this.Customer_detailTableAdapter.Fill(this.DataSet1.Customer_detail, Convert.ToInt32(textBox1.Text));             
             this.Bill_DetailTableAdapter.Fill(this.DataSet2.Bill_Detail, Convert.ToInt32(textBox1.Text));
             reportViewer1.LocalReport.Refresh();
             this.reportViewer1.RefreshReport();
         }

i have tried but it not works.how can i get current Bill no's detail in report viewer?



this is my report viewer from.this form takes bill no correctly but not print that bill no's data.
Posted
Updated 1-Apr-14 21:19pm
v2
Comments
Schatak 2-Apr-14 4:34am    
is billid primary key?
tejas.91 2-Apr-14 5:58am    
yes
Bernhard Hiller 2-Apr-14 8:15am    
int id = Convert.ToInt32(ds.Tables[0].Rows[0][0].ToString());
textBox1.Text = id.ToString();
this.Customer_detailTableAdapter.Fill(this.DataSet1.Customer_detail, Convert.ToInt32(textBox1.Text));
this.Bill_DetailTableAdapter.Fill(this.DataSet2.Bill_Detail, Convert.ToInt32(textBox1.Text));
Oh no!!!!!
int id = Convert.ToInt32(ds.Tables[0].Rows[0][0].ToString());
textBox1.Text = id.ToString();
this.Customer_detailTableAdapter.Fill(this.DataSet1.Customer_detail, id);
this.Bill_DetailTableAdapter.Fill(this.DataSet2.Bill_Detail, id);

well you can select max (billid) if it is a primary key and also you can select top 1 bill id in above query that you have write.
 
Share this answer
 
da = new SqlDataAdapter("select Max(billId) from Bill_Detail order by billId DESC", cn);
 
Share this answer
 
Comments
tejas.91 2-Apr-14 6:00am    
billId is reach on form2 but billid's data not displayed on report view.
use scope_identity to get last inserted row value

http://technet.microsoft.com/en-us/library/ms190315.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900