xpertwinner
Member
- Joined
- Dec 26, 2008
- Messages
- 24
- Programming Experience
- Beginner
I have a program which deals with submarines. The submarine has various modules, which in turn are composed of various components.
I have a database with a table of modules and a table of components, and a 1:N relationship between them, that is, a module has various components.
When I start my program, I copy the database to some objects in my program, so that the user can handle them in the way he wants. In the end, the user can save the final submarine back into the database.
However, I am having a problem saying cannot insert NULL ID in Modules, but I don't have any null ID, i have tried to debug. Here is the code:
Me.SubDataSet.Clear()
Dim compID As Integer = 1
For i As Integer = 0 To Submarine.Count() - 1
Dim row As SubDataSet.ModuloRow = SubDataSet.Modulo.NewModuloRow()
row.ID_Module = Submarine(i).ID_Module
row.Name = Submarine(i).Name
row.length = Submarine(i).Length
row.Position = Submarine(i).Position
SubDataSet.Modulo.AddModuloRow(row)
For j As Integer = 0 To Submarine(i).Components.Count() - 1
Dim comprow As SubDataSet.ComponentsRow = SubDataSet.Components.NewComponentsRow()
comprow.ID_Component = compID
compID += 1
comprow.ID_Module = Submarine(i).ID_Module
comprow.Name = Submarine(i).Components(j).Name
comprow.Material = Submarine(i).Components(j).Material
comprow.Volume = Submarine(i).Components(j).Volume
comprow.weight = Submarine(i).Components(j).Weight
comprow.buoyancy = Submarine(i).Components(j).Buoyancy
comprow.CGX = Submarine(i).Components(j).CGX
comprow.CGY = Submarine(i).Components(j).CGY
comprow.CGZ = Submarine(i).Components(j).CGZ
comprow.CBX = Submarine(i).Components(j).CBX
comprow.CBY = Submarine(i).Components(j).CBY
comprow.CBZ = Submarine(i).Components(j).CBZ
'SubDataSet.Componente.AddComponenteRow(row, Submarine(i).Components(j).Name, Submarine(i).Components(j).Material, Submarine(i).Components(j).Volume, Submarino(i).Components(j).Weight, Submarine(i).Components(j).Buoyancy, Submarine(i).Components(j).CGX, Submarine(i).Components(j).CGY, Submarine(i).Components(j).CGZ, Submarine(i).Components(j).CBX, Submarine(i).Components(j).CBY, Submarine(i).Components(j).CBZ)
SubDataSet.Components.AddComponentsRow(comprow)
Next
MsgBox("MODULE " & row.ID_Module & "ADDED")
Next
MsgBox("Nro of components" & SubDataSet.Componente.Rows.Count)
Me.Validate()
Me.ModuleBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.SubDataSet)
MsgBox("submarine saved")
The error is just in the UpdateAll line. I tried to translate the code to english, so dont worry if there are any errors in writing. thanks in advance.
I have a database with a table of modules and a table of components, and a 1:N relationship between them, that is, a module has various components.
When I start my program, I copy the database to some objects in my program, so that the user can handle them in the way he wants. In the end, the user can save the final submarine back into the database.
However, I am having a problem saying cannot insert NULL ID in Modules, but I don't have any null ID, i have tried to debug. Here is the code:
Me.SubDataSet.Clear()
Dim compID As Integer = 1
For i As Integer = 0 To Submarine.Count() - 1
Dim row As SubDataSet.ModuloRow = SubDataSet.Modulo.NewModuloRow()
row.ID_Module = Submarine(i).ID_Module
row.Name = Submarine(i).Name
row.length = Submarine(i).Length
row.Position = Submarine(i).Position
SubDataSet.Modulo.AddModuloRow(row)
For j As Integer = 0 To Submarine(i).Components.Count() - 1
Dim comprow As SubDataSet.ComponentsRow = SubDataSet.Components.NewComponentsRow()
comprow.ID_Component = compID
compID += 1
comprow.ID_Module = Submarine(i).ID_Module
comprow.Name = Submarine(i).Components(j).Name
comprow.Material = Submarine(i).Components(j).Material
comprow.Volume = Submarine(i).Components(j).Volume
comprow.weight = Submarine(i).Components(j).Weight
comprow.buoyancy = Submarine(i).Components(j).Buoyancy
comprow.CGX = Submarine(i).Components(j).CGX
comprow.CGY = Submarine(i).Components(j).CGY
comprow.CGZ = Submarine(i).Components(j).CGZ
comprow.CBX = Submarine(i).Components(j).CBX
comprow.CBY = Submarine(i).Components(j).CBY
comprow.CBZ = Submarine(i).Components(j).CBZ
'SubDataSet.Componente.AddComponenteRow(row, Submarine(i).Components(j).Name, Submarine(i).Components(j).Material, Submarine(i).Components(j).Volume, Submarino(i).Components(j).Weight, Submarine(i).Components(j).Buoyancy, Submarine(i).Components(j).CGX, Submarine(i).Components(j).CGY, Submarine(i).Components(j).CGZ, Submarine(i).Components(j).CBX, Submarine(i).Components(j).CBY, Submarine(i).Components(j).CBZ)
SubDataSet.Components.AddComponentsRow(comprow)
Next
MsgBox("MODULE " & row.ID_Module & "ADDED")
Next
MsgBox("Nro of components" & SubDataSet.Componente.Rows.Count)
Me.Validate()
Me.ModuleBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.SubDataSet)
MsgBox("submarine saved")
The error is just in the UpdateAll line. I tried to translate the code to english, so dont worry if there are any errors in writing. thanks in advance.