We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,394 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Update database from DataGridView

Hi,

I'm using C#, Access 2007 and VS2008 to write a windows app.

I have populated a datagridview from a query (taking data from 2 tables). When the user clicks "Save", I want to be able to save any changes made in the datagridview to the database. Only one column in the datagridview is editable, so any changes will be made to just the one table in the database.

I could possibly do something using the CellEndEdit event, but that would fire for each cell that is updated, which is a bit clunky.

So, can anyone please tell me how I can write data back to the database, when the original datagridview is populated from a query?

Thanks in advance,
Jon

4
Contributors
3
Replies
3 Months
Discussion Span
3 Years Ago
Last Updated
7
Views
Question
Answered
jonnod123
Newbie Poster
23 posts since Nov 2009
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0

Here is a link that shows you how to execute an update command on the table: http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.updatecommand.aspx

DdoubleD
Posting Shark
996 posts since Jul 2009
Reputation Points: 341
Solved Threads: 233
Skill Endorsements: 3
Question Answered as of 3 Years Ago by DdoubleD

Hi,

I'm using C#, Access 2007 and VS2008 to write a windows app.

I have populated a datagridview from a query (taking data from 2 tables). When the user clicks "Save", I want to be able to save any changes made in the datagridview to the database. Only one column in the datagridview is editable, so any changes will be made to just the one table in the database.

I could possibly do something using the CellEndEdit event, but that would fire for each cell that is updated, which is a bit clunky.

So, can anyone please tell me how I can write data back to the database, when the original datagridview is populated from a query?

Thanks in advance,
Jon

Hello Jon,

For datagridview, you MUST have one Primary key in your database.

Try it out and let me know if you have any problem.

Also Please see: http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/666835a2-50ec-415f-ba30-bb80ca51c91b

i_microsoft
Newbie Poster
1 post since Jul 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Welcome @i_microsoft.

We appreciate your knowledge. Please do not resurrect old/solved thread.

Thread Closed.

__avd
Posting Genius (adatapost)
Moderator
8,736 posts since Oct 2008
Reputation Points: 2,141
Solved Threads: 1,262
Skill Endorsements: 50

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0597 seconds using 2.64MB