Click here to Skip to main content
15,039,470 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
if (txtcombo.Text == "Form ID")
                {
                  
                    label1.Hide();
                    Global.Open_DataConn("doc", "conData");
                    OleDbDataAdapter da = new OleDbDataAdapter("SELECT WCDCH.formid, WCDCH.surname, WCDCH.firstname, WCDCH.midname, WCDCH.ttransid FROM WCDCH INNER JOIN bankdata ON WCDCH.formid = bankdata.formid", Global.conData);
                    DataSet ds = new DataSet();
                    da.Fill(ds);
                    dataGridView1.DataSource = ds.Tables[0];
                    label2.Show();
                    label4.Visible = true;
                    label3.Text = dataGridView1.RowCount.ToString();     
                }
                else if (txtcombo.Text == "TransactionID")
                {                  
                    label2.Hide();
                    Global.Open_DataConn("doc", "conData");
                    OleDbDataAdapter da = new OleDbDataAdapter("SELECT WCDCH.formid, WCDCH.surname, WCDCH.firstname, WCDCH.midname, WCDCH.ttransid FROM WCDCH INNER JOIN bankdata ON WCDCH.ttransid = bankdata.ttransid", Global.conData);
                    DataSet ds = new DataSet();
                    da.Fill(ds);
                    dataGridView1.DataSource = ds.Tables[0];
                    label1.Show();
                    label4.Visible = true;
                    label3.Text = dataGridView1.RowCount.ToString();           
                }
                else
                {
                    MessageBox.Show("Please,Select option which you want");
                }      
            } 

I have done the get matching record from the database in datagrid and count the record from result shown in the datagrid, But the count shows the 1 extra record count.
Posted
Updated 16-Jun-12 0:25am
v3

Change it to row count of datasource instead of grid. It might have header row counted in it.
C#
label3.Text = dataGridView1.RowCount.ToString(); 
label3.Text = ds.Tables[0].Rows.Count.ToString();
   
Comments
Amit Bhoi 16-Jun-12 6:42am
   
Thanx sandeep it works.....
Sandeep Mewara 16-Jun-12 7:00am
   
Welcome.
member60 16-Jun-12 7:33am
   
my 5!
Sandeep Mewara 16-Jun-12 9:01am
   
Thanks.
Robin La 17-Jun-12 9:31am
   
Good Answer.
Sandeep Mewara 17-Jun-12 11:38am
   
Thanks.
change this :
C#
label3.text = ds.Tables[0].Row.Count.ToString();

and then bind the grid.
   
v2
Comments
member60 16-Jun-12 7:34am
   
my 5!

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