Could you perhaps supply me with some code to update to the database
because I don't get it yet.
As I understand the wizard is useless now that I have related tables
The automatic update will not work.
Hmm.. I never had a problem with related tables.. nothing is done differently, but you MUST remember that if you have an FK enforcing your relationship, that parent records must be created first. The following code is an example:
Private Sub NamesBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ParentBindingNavigatorSaveItem.Click
Me.Validate()
Me.ParentBindingSource.EndEdit()
Me.ParentTableAdapter.Update(Me.MyDataSet.Parent)
Me.ChildBindingSource.EndEdit()
Me.ChildTableAdapter.Update(Me.MyDataSet.Child)
End Sub
From msdn I have a sample that will create a customAdapter with some insert, add, and Update commands created, but it's still too narrow. It doesn't consider relational data.
No, it wont.. the data access layer doesnt care about your relationships - all a relationship does if filter and show children of the currently shown parent. You must still:
Fill the parent data
Fill the child data
Save the parent data
Save the child data
yourself
Also, do I have to rearrange my whole way of thinking, because if I create a new adapter I can not use anything that is automaticly created when I drag the table out off the datasources window? I loose control off the navigatorcontrol and what about the other table that's in details modus. Do I have to do a lot manually now, as in typing?
Um.. not really. You dont really say what youre having trouble with, but basically, ref my paragraph above, about fill parent, fill child, edit either, save parent, save child - thats the order you do it in, and you ahve to do that yourself. The code you msut do isnt exactly a lot.
Read the DW2 link about displaying related data, and saving related data
[SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] System.Data.SqlClient[/SIZE]
[SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE][SIZE=2] FDataBase[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] cs [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#a31515]"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\TDB.mdf;Integrated Security=True;User Instance=True"[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] sSQLSelect1 [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#a31515]"Select * from Orders"[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] sSQLSelect2 [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#a31515]"Select * from Customers"[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] da1 [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] SqlDataAdapter(sSQLSelect1, cs)[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] da2 [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] SqlDataAdapter(sSQLSelect2, cs)[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] myDataSet = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] DataSet()[/SIZE]
'or in one adapter
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] ss [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#a31515]"SELECT * FROM Customers; SELECT * FROM Orders"[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] da [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] SqlDataAdapter(ss, cs) [/SIZE][SIZE=2][COLOR=#008000]'cs is my connectionstring[/COLOR][/SIZE]
[SIZE=2][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] FormMain_Load([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]MyBase[/COLOR][/SIZE][SIZE=2].Load[/SIZE]
[SIZE=2]da1.Fill(myDataSet, [/SIZE][SIZE=2][COLOR=#a31515]"Orders"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]da2.Fill(myDataSet, [/SIZE][SIZE=2][COLOR=#a31515]"Customers"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]'Just the gridview[/SIZE]
[SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].JobsDataGridView.DataSource = myDataSet[/SIZE]
[SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].JobsDataGridView.DataMember = [/SIZE][SIZE=2][COLOR=#a31515]"Orders"[/COLOR][/SIZE][/SIZE]
No, no, no.. you've done all this already; you have a tableadapter with this code in. You dont ned to duplicate it here, all you do is call the Update() command of the table adapter, passing a datatable with modified rows, and the changes are sent back to the database.
Whatever tutorial you got this out of, throw it away; its 2 years out of date at least