Windows Develop Bookmark and Share   
 index > Windows Forms General > Refreshing a datagrid in a WinForm
 

Refreshing a datagrid in a WinForm

I'm not sure if this is the right forum but I couldn't find a Winform forum, everything kept pointing me back to this forum.

Anyway, I have created a simple WinForm and dropped a DataGridView onto it. I went through the wizard and picked a table in my SQL database, automatically created a connection etc. The data appears fine.

When I add a record to my database table though, the grid on the form does not update.

I've tried:
1. Re-specifying the data source again.
2. Invalidate
3. Invalidate + Refresh

I can see my data in the table so I know it's there.

Second thing is, if I go manually delete all the records in the table, and restart my application, I still see the data in the grid!

Its been a long time since I've worked with grids and winforms but I'm thinking I'm missing something simple here.

Any ideas?

Thanks!
  • Moved byJim Zhou - MSFT Monday, September 28, 2009 1:18 PMWindows Forms related issue (From:Windows Presentation Foundation (WPF))
  •  
stombiztalker  Thursday, September 24, 2009 3:16 PM
Sounds like you are not re-reading from the database or sending changes back to the database. You need to use the DataAdapter to refill your tables (from the database) and to send changes back to the database.
wjousts  Thursday, September 24, 2009 3:30 PM
Sounds like you are not re-reading from the database or sending changes back to the database. You need to use the DataAdapter to refill your tables (from the database) and to send changes back to the database.
wjousts  Thursday, September 24, 2009 3:30 PM
Hi Stombiztalker ,

Since this is WPF forum, while your issue is related to Windows Form, so I am moving this thread to the Windows FormForum, there are more expertsin that field.

Thanks.
Sincerely.


Jim Zhou -MSFT
Jim Zhou - MSFT  Monday, September 28, 2009 1:17 PM

As @wjousts said, you need to save changes to the database.

If you bind a datagridview control to a datatable which data is got from database, you have got the datagridview bind to the datatable instance. Any Changes of the datatable will not impact the database.

Useful link:

How To Update a SQL Server Database by Using the SqlDataAdapter Object in Visual C# .NET

http://support.microsoft.com/kb/308507/en-us

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Wednesday, September 30, 2009 2:09 PM

You can use google to search for other answers

Custom Search

More Threads

• show form without knowing name of form
• Creating an excel stylesheet using C#
• Drawing complex math functions like sin, cos, arcsin...
• TreeView image quality
• Mouse Wheel doesn't Work in AutoScroll Panel with PictureBox
• Winform question
• Detecting if a font family has a bold font
• Printing Multiple Pages in C#
• login to the windows form application
• Certificate Details in Web Browser