Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

SQL
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
Updated 15-Oct-13 4:22am
v3
Comments
[no name] 8-Jul-13 17:54pm    
Any solution to what? Requery the data.

Requery the data after clicking the Save Button.
 
Share this answer
 
Comments
mareksip 9-Jul-13 4:48am    
Would you please help me with the code?
berrymaria 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
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
 
Share this answer
 
Comments
mareksip 9-Jul-13 3:46am    
Would you please help me with the code?
Member 12341349 17-Apr-16 12:05pm    
yes
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.
 
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