Bound Form : Going to specific record + Updating data

Ace1000

Member
Joined
Aug 29, 2015
Messages
8
Programming Experience
1-3
I have Visual Studio 2015 Express with SQL Server Express 2014
I am new to .NET but have solid experience with Access/VBA.
I have dragged and dropped fields from tblProductDetails in my Datasource tab into Form1 to create bound fields.


Now I am struggling with two things.

ISSUE #1. Going to a specific record from another form.
--------------------------------------------------------------------------
Form1 has textbox (txtProductID) where I can type an integer.

Form1 has a button which when clicked opens Form2 (frmProductDetails) that has the bound form fields from table (tblProductDetails).

I know how to pass the value in txtProductID in Form1 to Form2.
However, I don't know how to pull all the data for this specific ProductID. eg...suppose I wish to see the details for ProductID=15
Form2 currently opens the 1st record (ProductID = 1) in tblProductDetails.

I have VBA/Access experience so I just need a general direction.




ISSUE #2. Update table upon change in form.
--------------------------------------------------------------------
The bound Form2 does not update when I change data in the dropdowns and textboxes.

Do I need to write further code to update the underlying table when I update the values in the fields in Form2?
Are there setups in design-time that can do this job?


Thanks in advance.


 

IanRyder

Well-known member
Joined
Sep 9, 2012
Messages
1,130
Location
Healing, NE Lincs, UK
Programming Experience
10+
Hi,

Since you have added a DataSource to your project and bound the fields to the form from that DataSource then a BindingSource would have been automatically added to your form and it is this BindingSource that then allows you to Navigate and Filter data within your DataSet. Have a look at these two links for navigation and filtering:-

BindingSource.Find Method (String, Object)
BindingSource.Filter Property

With regards to the second question, when you dragged the first control onto the form from the DataSource then this should have added a default BindingNavigator at the top of the form with some default code to save your changes under the Save Button Item. This should look something like this:-

Private Sub SomeTableBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles SomeTableBindingNavigatorSaveItem.Click
  Me.Validate()
  Me.SomeTableBindingSource.EndEdit()
  Me.TableAdapterManager.UpdateAll(Me.TestDataSet)
End Sub


If this is not there then I would suggest you have made a mistake somewhere and to give it another go.

Hope that helps.

Cheers,

Ian
 

Ace1000

Member
Joined
Aug 29, 2015
Messages
8
Programming Experience
1-3
Thanks Ian,

BindingNavigator is there, because I added it from the Toolbox later.
I don't see the 5 lines of BindingNavigator_Click code that you have mentioned.
Question 1 : Can I add it to the click event to the Save button?


Question 2 : How do I know if there is a BindingSource ? Is there a visual control I should see or is there another way to tell?

I can email you a screenshot but I prefer not to put it on the forum directly.

Thanks
 

IanRyder

Well-known member
Joined
Sep 9, 2012
Messages
1,130
Location
Healing, NE Lincs, UK
Programming Experience
10+
Hi,

The fact that you said:-

BindingNavigator is there, because I added it from the Toolbox later.

Means that you did not do it right in the first place so my suggestion would be to start again and:-

1) Add the DataSource
2) Change the Table from DataGridView to Details
3) Drag the Table to a New Form

You should then see something like:-
Capture.png

As you can see the Fields have been added to the Form, the Navigation Tool Bar has been added to the top of the form and the Data Access Objects have been added which can be seen below the form. As well as this, the following code should be added by default:-
Capture2.PNG

And that’s it. Easy?

Of course, you can do all of this manually without using the built in tools but you are going to need a bit more knowledge until you get to that stage so I would suggest that you concentrate on getting this bit right first so you know where things went wrong the first time.

Good luck and hope that helps.

Cheers,

Ian
 
Top Bottom