|
-
Feb 8th, 2018, 10:12 AM
#6
Re: Is datagridview like excell
In the past, you had a more direct tie between the DB and the display (not a DGV, but something close). That meant that you had to be connected to the DB ALWAYS! That really sucks for multiple users. Connections aren't unlimited, and can have some implications for some databases. You had to take that into account. For example, if you are viewing row R and somebody else wants to edit row R....what happens? It might work, or you might have locked the record, or the change might happen behind you, or whatever. Furthermore, every time you change records, you have to make a round trip to the database to get whatever new information is needed. You might think that's not so bad, because you load ALL the data into the display, but that is likely not how the grid works. It may or may not have all the records in memory. It may have only those that need to be drawn to the screen. The other data is not there, yet. So, you might be going back and forth to the DB frequently. This will pretty much HAVE to be true if you want to be able to edit any of the records, because the only place the edit can happen is against the DB. Not only does this require the data to flow back and forth to the DB, it has to be able to identify the row, which will mean more data is flowing than JUST the edit. If the connection is across a slow wire, you can imagine what this would do to performance.
The way it works with a datatable is that you open a connection, fill the datatable, then close the connection. All the work is now done against that copy of the data in the datatable. Any round trips (the same issues still apply) are now round trips to local RAM, which takes nanoseconds, rather than round trips to a database wherever it might be located, which can take many milliseconds, or worse. Also, you aren't locking any records, except for the tiny amount of time needed to fill the datatable (less than that, really). If somebody changes the records you have brought in to the datatable, it doesn't affect you any, until you push your updates back to the database, at which time the DB applies rules to decide what to do with the updates (lookup optimistic concurrency for more on this). So, you have faster performance, you aren't tying up a DB connection for long times, and you aren't locking database records. I may have overlooked some benefits, but those are good enough to justify using a datatable rather than a direct connection.
My usual boring signature: Nothing
 
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|