I am hoping that someone from the forum is familiar with the Doing Objects in Visual Basic 2005 book so that this question makes a little more sense. I have completed the sample project and understand most of what I have done. There are some holes in my knowledge but I am sure I will pick up those pieces as I become more familiar with object orientated programming.
The sample project is an almost complete application where you view and edit Objects that are stored in a database. The author leaves the remaining features needed up to the reader, which is great because I have been able to put new knowledge into use. However I am having trouble saving a new object back to the database.
I think this is the proper way to add a new object to the binding source
VB Code:
Public Function ProcessNew() As Boolean Implements IMDIChild.ProcessNew Dim myGoal As Goal = TryCast(GoalBindingSource.AddNew, Goal) myGoal.Save() End Function
And I think this block of code from the Class has everything it needs to save back to the database
By looking at this code it appears that I can save the data that is in the bindingsource by changing the EntityState to the Enum added. However I am not sure where to set it. I am pretty confident that I have the rest of this correct because when I try to do the save I get an error that the stored procedure is expecting the GoalID.VB Code:
Public Function Save() As Boolean Dim dt As DataTable = DAC.ExecuteDataTable(My.Resources.sp_Update, _ DAC.Parameter(CN_GoalID, GoalID), _ DAC.Parameter(CN_Goal, Goal), _ DAC.Parameter(CN_RowState, EntityState.ToString)) If EntityState = EntityStateEnum.Added Then GoalID = CType(dt.Rows(0).Item(CN_GoalID), Integer) End If DataStateChanged(EntityStateEnum.Unchanged) Return True End Function




Reply With Quote