Sharing the goodness…
Beth Massi is a Senior Program Manager on the Visual Studio team at Microsoft and a community champion for business application developers. Learn more about Beth.
More videos »
Yesterday I posted the first 8 videos of the Visual Basic Forms over Data "How-to" video series on MSDN. These videos are for those who are just starting out with databases and Windows Forms data binding. I plan on continuing the series with more intermediate topics like custom object binding, adding validation and business logic, and how to manage requirements changes. What kind of topics are you interested in seeing here? Post a comment or drop me a line and let me know.
Those interested in the sample code I created in this series so far, see the attachment to this post.
Enjoy!
Just wanted to say how great this video series is. Beth, you did a fantastic job and you have an exelent skill for teaching. I'd love to see more. Maybe more complex data forms and data structures, working with MDI forms, Interop Forms... Just things that I'd find interesting personally.
Cheers!
Same comments as above. Great Videos
I have the same problem as Bob has, when I try to delete an order line the program deletes everything for that customer and the throws the error that Bob mentions, I have checked all the Foreign Keys and the stored procedures without comeing up with anything, please, what am I doing wrong?
Other that that , a great series.
Hi Bill,
This is how databases work. You'll need to delete all the order details and orders before deleting the customer. Place a Try...Catch around the call to TableAdapter.Update and put up a messagebox that "This customer has orders and cannot be deleted" or change the referential integrity to CASCADE the deletes to the orders when the customer is deleted. For more information on referential integrity check out the SQL-Server Books Online or you may want to check out the Data video series on www.asp.net.
Cheers,
-B
Hi Beth.
Thankyou for the swift reply to my post.
I don't think that I made my problem quite clear in my original post.
I am following your Video Number 3 , One to Many.
I have created the two grids, fine, they both work on Add and Amend.
But, if I Add an Order line to the Order Grid, it works, then if I save it and end the program on startup everything is fine, the posting of the additional line of the order is there.
I can amend it , no problem.
When I delete the Order Line it deletes all the orders for that customer and deletes the Customer, thats my problem. The Customer is deleted when I try to delete an Order
Regards
Bill
How are you deleting the Order Line? You need to make sure and either call the BindingSource.RemoveCurrent() method on the OrderLine's BindingSource or select the line in the grid and hit the delete key. It sounds like you are actually deleting the customer by clicking the Delete icon on the BindingNavigator which is attached to the Customer.
Can you check that?
Hi Beth
Thankyou for your answer, I assumed, wrongly it turns out, that by clicking on the Delete Icon on the BindingNavigator it would delete the order line.
Slapped Wrists !!!
It works perfectly now.
Thank you
Hi Beth,
Thanks for the excellent tutorial! As an absolute beginner, I was going nowhere trying to figure this out myself. Your video's really helped me understand things.
Thanks!
Dennes
Hi, I'm a starter programmer here in Latin America, thank you for your videos, which are a great tool for new starter programmers, reaching schools all arround our country, thank you for showing the way of doing things easy not like those books and web pages that make you feel programming is further than the stars.
I want to make a question; How do I make a change connection string form, to let the user do the look for the database work if needed?
All of our best,
Latin Programmer
Hi Luis,
The connection strings are stored in the applicaiton's .exe.config file. You can change this on a user's machine by finding the loacation of the exe and looking for the *.exe.config where * is the name of your assembly. Open that file with any text editor and you can adjust the connection string. You can also do this through the program by changing and then saving the user settings. Have a look here for more information: http://www.devsource.com/article2/0,1759,2089353,00.asp
HTH,
I'm new to .Net. I have created a vb project which is connected to a table in database. I have created my own ADD, SAVE, DELETE buttons on the Binding Navigator. the prob. is that when I click DELETE, it always deletes the first record in the database table rather than the current record even though I used (me.MyBindingSource.RemoveCurrent)
the code is:
Private Sub NavigatorDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NavigatorDelete.Click
Dim msg As String = "Are you sure you want to delete this record?"
Dim title As String = "Delete Record(s).."
Dim Style As MsgBoxStyle = MsgBoxStyle.YesNo
Dim result As MsgBoxResult
result = MsgBox(msg, Style, title)
If result = MsgBoxResult.No Then
Exit Sub
End If
If result = MsgBoxResult.Yes Then
Me.DVDsBindingSource.RemoveCurrent()
Me.Validate()
Me.DVDsBindingSource.EndEdit()
Me.DVDsTableAdapter.Update(Me.DVDStorageDataSet.DVDs)
MsgBox("Record deleted.", MsgBoxStyle.Information, title)
AllNotes.Text = "Record has been permenantly deleted."
If Me.DVDsBindingSource.Count = 0 Then
Me.DVDsBindingNavigator.Enabled = True
'it works only if I use the following, that is why I think there is
'something wrong with the confirmation
'Me.DVDsBindingSource.RemoveCurrent()
End Sub
Hi Kas,
When you call Update on the TableAdapter the position will move to the first row. It's best practice to NOT call update after every action as this is not scalable. Instead, only call update when the user clicks Save after they have made edits to the entire form. The other thing you can do in your Save routine is to save the BindingSource.Position in a variable and then reset it after the update.
I just started with the first video and I would like to know how to use the OMS.mdf file that is provided? which directory do you put the file in and how do you open the database?
When I tried to open it I am getting and error that file already exists and the attech aborts.
Using visual studio 2008...
Love your videos, I would like to see more more videos on windows forms applied to scenarios containing a dataset with more than 2 tables, like Orders OderDetails And Products. Videos on how To handle Many to many relationship updating inserting and deleting using DataBinded textbox not the usual examples with the DataGridView.
Thank you for your work
Thank you for your videos. It makes learning fun.
I have a small question on the bindingnavigator (with reference to your video on adding validation.)
Assume a table that has fields that do not accept NULL.
What to do in the case where the user presses the addnew button on the navigator twice in a row?
It raises an exception everytime and catching it seems a bit of a nightmare.
Kind Regards,
James