0

I have loaded data from an Excel sheet via SqlBulkCopy into a SQL Server 2016 database. Then I have loaded this table into a datagrid in C# & WPF.

Some cells are empty, and if I write something in them, I want to immediately (right after I pressed Enter or click on another cell) update my database.

I've looked up many solutions on the internet but none of them helped me.

Thank you in advance and have a nice day!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
F.Gradl
  • 39
  • 10
  • 2
    Seems **highly inefficient** to constantly update the database for each cell, when you write something into them ...... usually, you'd wait until you leave the row and then update the database with all changes for that one row and move on – marc_s Aug 23 '17 at 09:09
  • despite being inefficient it doesnt sounds like you have much googlefu if you couldnt find how to update a db – BugFinder Aug 23 '17 at 09:11
  • Hey @marc_s, each row has round about 16 columns and only two to tree of them are empty, and the reason why i need this value is because i have to do some calculation right after the input. – F.Gradl Aug 23 '17 at 09:13
  • @BugFinder every time i google it, it shows me the diffrent way like 'update your datagrid after database changes' or something like that – F.Gradl Aug 23 '17 at 09:15
  • @F.Gradl clearly poor google fu i get plenty of answers of how to save dataview changes to database and none are the way round you're getting – BugFinder Aug 23 '17 at 09:22
  • https://stackoverflow.com/questions/10683570/updating-datagridview-values-into-database – BugFinder Aug 23 '17 at 09:23
  • @BugFinder Datagrid and Dataview aren't the same or am i wrong? – F.Gradl Aug 23 '17 at 09:25
  • the principles are the same – BugFinder Aug 23 '17 at 09:26
  • Ok I'm sorry! my fault! i will look it up again and hope to find what i'm looking for! Have a nice day – F.Gradl Aug 23 '17 at 09:28

1 Answers1

0

You can use your datagrid's events:

Leave : Occurs when the DataGridView loses focus;

CellLeave : Occurs when a cell loses focus, i.e. it's no longer the current cell;

RowLeave : Occurs when a row loses focus and is no longer the current row;

red9350
  • 338
  • 3
  • 11