|
-
Aug 28th, 2007, 04:27 PM
#1
Thread Starter
Hyperactive Member
Using tableadapter to update
#1 When I use my xxxTableAdapter.Update method, does that write back only changes? It doesn't write back the entire dataset, does it?
#2 I intend to have multiple users accessing the same table, making record edits and updating. I want to do some kind of record locking when each user is editing a specific row. Can I do that using the tableadpater.update method somehow?
#3 I also am using a bindingnavigator with the datagridview. When a user edits a row, I pass the row values to another form, let them edit, and pass them back. I'm having trouble getting the datagridview to reflect the changes. I have some code that sort of works, but not always. Any suggestions?
-
Aug 28th, 2007, 05:02 PM
#2
Re: Using tableadapter to update
1. There is a rowstate property for each datarow. The update method checks these states an "updates" the database based on them. This includes inserts and deletes (update maybe a confusing name for this method). That also assumes you've setup your adapter's insert and delete commands. It sounds like you're after a single row update, so the best solution maybe a command object and the ExecuteNonQuery method.
2. As far as I know the adapter does not nativly support locking a record.
3. Hard to help you out without a code sample, and a better description of the problem.
-
Aug 28th, 2007, 06:06 PM
#3
Thread Starter
Hyperactive Member
Re: Using tableadapter to update
Thanks Bill...Re: your answer to #1...Do you mean to use Command object to do the initial query to fill the datagridview? If so, is it easy to unbind the datagridview (or don't I have to do this?) and fill it using a command object query?
I was thinking that, but don't know how to begin without starting over. help
-
Aug 28th, 2007, 06:15 PM
#4
Re: Using tableadapter to update
The answer to question 3 is so ridiculously easy you will kick yourself. You don't have to do anything to get the grid to update, which is the whole point od data-binding. You simply have to update the DataRow and the grid will do the rest for you.
http://www.vbforums.com/showthread.php?t=469518
-
Aug 28th, 2007, 08:08 PM
#5
Thread Starter
Hyperactive Member
Re: Using tableadapter to update
jmc--You once pointed someone once to a sample on how to do master/detail with a bound datagridview and I tried it but got stuck on when adding a new row with the bindingnavigator's "add" button--if the user canceled, a the row would still be added. Here was my original post:
http://www.vbforums.com/showthread.php?t=483581
But no one answered and I gave up and instead passed the row data to the form, passed it back, updated the grid on edit or inserted on add--only if the user didn't cancel.
I may try what you say again, now that I'm not using the bindingnavigator's add and delete buttons, but using my own.
I'm sorry, I'm really don't have the big picture, as you can tell. If you can add anything to this, I would appreciate it, you really know your stuff.
-
Aug 28th, 2007, 08:25 PM
#6
Re: Using tableadapter to update
There's no need to not use a BindingNavigator just because of that. The BindingNavigator has default behaviour but that can easily be changed. For instance, the Add button is assigned by default to the AddNew property, so pressing that button executes the default action for adding a new record. If you don't want that then you simply clear the addNew property and handle the Click event of the Add button yourself, allowing you to do whatever you want.
This is the sort of thing that illustrates why it's important to read the documentation for the classes you're using. If you don't know what they can do then how can you possibly know you're using them properly? I know most of what I know because I take the time to read.
-
Aug 29th, 2007, 04:49 AM
#7
Thread Starter
Hyperactive Member
Re: Using tableadapter to update
You're right about reading the doc. I didn't think until just now to hit F1 on the contol--and you actually get useful help. Before I was scouring the index and could not find properties and methods for controls. Silly me.
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
|