Visual Studio .NET - run insertcommand.transaction

Asked By David on 03-Mar-11 05:00 PM
Hi

I now have my Tableadapter insertcommand working correctly and when I run the query it asks for Prikey No and when the relevant number/selection is entered it puts one row of Data from Table 1 into Table 2

How do I get this to run from (BindingNavigatorAddNewItem) button  on my DataGridView Form when project is running.
 I want to just click the button and the selected cell Prikey number/row is inserted.


Thanks  David
Vic S replied to David on 04-Mar-11 03:45 PM
In Visual Studio from the designer window you will be able to see your bindingnavigator at the bottom of the screen underneath the dgv. Right-click on it and click on Properties.  The AddNewItem property should be set to BindingNavigatorAddNewItem. If not set it to that.
The Bindingsource should be set to your bindingsource.
That should be all you need.
David replied to Vic S on 04-Mar-11 04:30 PM
Hi Vic

Thanks for the reply
I have got the ( BindingNavigatorAddNewItem ) button on the binding navigator bar I need the code to make this run the insert command from my DatasetTableadapter and insert the selected Prikey (number row selected)
If I click on it now it just inserts a blank line what I need it to do is insert from Table 1 to Table 2 like it does in the DatasetTableadapter when the query is run.


Thanks

David
Vic S replied to David on 04-Mar-11 05:12 PM
If I understand the issue the insert command then is running but you need to pass it a value before it does?
If so try doing that in your BindingNavigatorAddNewItem_Paint event.
Or you could disconnect the addnewitem from the bindingnavigator and then in the BindingNavigatorAddNewItem_Click event you could pass the value and issue your adapter update so it would do the insert..
David replied to Vic S on 04-Mar-11 05:46 PM
Hi Vic
 
your suggestion sounds what I need but I am unsure how to code the Button to make it operate the adapter command
or do I make a new button on the Datagridview page.

Or you could disconnect the addnewitem from the bindingnavigator and then in the BindingNavigatorAddNewItem_Click event you could pass the value and issue your adapter update so it would do the insert..
 Thanks

David
Vic S replied to David on 07-Mar-11 09:45 AM
First in your datagridview design screen right-click on your bindingnavigator and select Properties. Change the AddNewItem property to None. This will make it not add automatically when user clicks on the AddNewItem button of the bindingnavigator. You will need to enter your own code to do that. So in your code under the BindingNavigator_Click event enter the code to do that. It would be something like:
Yourbindingsource.EndEdit()
yourtableadapter.Update(yourDS,yourParm)
yourDS.AcceptChanges()