Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Windows Application
Hello all,
 
I really want to know how can I pass a whole datagridview values to another datagridview in another form? using c# windows application.
 
i have two form ,
 
form1:
i have one search option which is have,
one text box and one search button,
when i type something related to the table field in my text box and click search button,
 
the corresponding data has displayed to another form datagridview, that means form2.
 
form2:
 
i have only datagridview.
 
please my code see below where i did mistake my code and let me know the solution please..
 
my code is:

 
form1:
 
private void button1_Click(object sender, EventArgs e)
{
      try
      {
            if (textBox1.Text == "")
            {
                 MessageBox.Show("Please Enter the Input Key.", "Error Message");
            }
            else
            {
                 DataTable dataTable = new DataTable();
                 con = new SqlConnection(s);
                 con.Open();
                 cmd = new SqlCommand("select Destinations,TimeofDay,DialCode,EffectiveDate,NewOffer from RateSheets where Destinations='" + textBox1.Text + "'", con);
                 SqlDataReader sqlDataReader = cmd.ExecuteReader();
                 dataTable.Load(sqlDataReader);
                 con.Close();
                 form2 fm = new testing();
           
                 fm.Show();
                 dataGridView1.DataSource = dataTable;
             }                   
       }                   
       catch (Exception ex)
       {
             MessageBox.Show(ex.ToString());
       }
}
Thanks in advance...
Posted 26-Feb-13 3:29am
v2
Comments
Orcun Iyigun at 26-Feb-13 8:43am
   
maybe you may want to change your where statement with LIKE '%textbox1.text%' instead of equals. In your current code do you have any exceptions?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
Member 9989542 at 18-Apr-13 0:54am
   
i have two tables sql (database name vijay)
table1 table2
 
name age sex name marks1 marks2 total
vijay 15 m vijay 50 45 95
ramu 14 m vijay 45 60 105
ram 15 m ram 50 45 95
lux 15 f ramu 50 45 95
ramu 50 55 105
lux 50 45 95
 
i make these two tables in two gridview in c# windows form
nw when i click the 1st gridview row (name) , i need to filter name which present in second gridview and show that data in secondgridview
i need a stored procedure and need to call that in c#...
 
ex
when i click name vijay in firstgridview i need like below in secondgridview
name marks1 marks2 total
vijay 50 45 95
vijay 45 60 105
Orcun Iyigun at 18-Apr-13 2:36am
   
why would you need to do the binding in the stored procedure?? HAve a look at this link[^]. It is gridview's click events. You can use cell click event and on this event you can bind your second gridview to filter your results. It is more easier in my opinion.

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

  Print Answers RSS
0 OriginalGriff 565
1 Maciej Los 319
2 Richard MacCutchan 220
3 BillWoodruff 164
4 Mathew Soji 160
0 OriginalGriff 8,654
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,229
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 26 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100