Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# SQL DataGrid
Hello guys,
 
I have DTG in form1 and I'm inserting values in it using SQLCommand.
When I click button SAVE in form2(which also closes form2) I would like to refresh form1's datagridview.
 
Is there any solution?
THanks so much.
 
SqlCommand prikaz = new SqlCommand
                    ("INSERT INTO ..);
spojeni.Open();
                prikaz.ExecuteNonQuery();
                System.Data.DataTable dt = new System.Data.DataTable();
                System.Data.SqlClient.SqlDataAdapter SDA = new System.Data.SqlClient.SqlDataAdapter("...", spojeni);
                SDA.Fill(dt);
 
Posted 8-Jul-13 12:28pm
Edited 15-Oct-13 5:22am
v3
Comments
ThePhantomUpvoter at 8-Jul-13 17:54pm
   
Any solution to what? Requery the data.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Requery the data after clicking the Save Button.
  Permalink  
Comments
Marek Šíp at 9-Jul-13 4:48am
   
Would you please help me with the code?
coelirosea at 9-Jul-13 5:39am
   
Hi, please see this examples:
 
http://stackoverflow.com/questions/14374348/refresh-button-refreshing-data-grid-view-after-inserting-deleting-updating
 
http://stackoverflow.com/questions/15526067/c-sharp-refresh-datagridview-when-updating-or-inserted-on-another-form
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

May be this help you
While closing the form2 you call the Constructor of form1 and write the logic to update the grid in the constructor
  Permalink  
Comments
Marek Šíp at 9-Jul-13 3:46am
   
Would you please help me with the code?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Well,
after you complete you process inserting data in form2 you have to bind form1 grid again on page load event because if you are not bind it or not refresh that form it should saw old record so you have to write code on page load for binding grid.

This will definitely solve you problem:

http://stackoverflow.com/questions/7797975/how-to-refresh-a-form-from-another-form[^]

http://stackoverflow.com/questions/15896135/how-to-reload-form-in-c-sharp-when-button-submit-in-another-form-is-click

And accept as solution and vote if solve your problem.
  Permalink  

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

  Print Answers RSS
0 Mathew Soji 330
1 BillWoodruff 260
2 Sergey Alexandrovich Kryukov 240
3 OriginalGriff 216
4 Afzaal Ahmad Zeeshan 208
0 OriginalGriff 6,168
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,028
3 Manas Bhardwaj 4,539
4 Maciej Los 3,845


Advertise | Privacy | Mobile
Web03 | 2.8.1411019.1 | Last Updated 15 Oct 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