1,105,271 Community Members

Update database from DataGridView

Member Avatar
jonnod123
Newbie Poster
22 posts since Nov 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
DdoubleD
Posting Shark
984 posts since Jul 2009
Reputation Points: 315 [?]
Q&As Helped to Solve: 235 [?]
Skill Endorsements: 5 [?]
 
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

Question Answered as of 4 Years Ago by DdoubleD
Member Avatar
i_microsoft
Newbie Poster
1 post since Jul 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
-2
 

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

Member Avatar
__avd
Posting Genius (adatapost)
6,703 posts since Oct 2008
Reputation Points: 1,811 [?]
Q&As Helped to Solve: 1,272 [?]
Skill Endorsements: 61 [?]
Moderator
 
1
 

Welcome @i_microsoft.

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

Thread Closed.

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article