Results 1 to 6 of 6

Thread: Doing Objects in Visual Basic 2005 Project Question

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2010
    Posts
    4

    Doing Objects in Visual Basic 2005 Project Question

    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:
    1. Public Function ProcessNew() As Boolean Implements IMDIChild.ProcessNew
    2.         Dim myGoal As Goal = TryCast(GoalBindingSource.AddNew, Goal)
    3.         myGoal.Save()
    4.     End Function

    And I think this block of code from the Class has everything it needs to save back to the database
    VB Code:
    1. Public Function Save() As Boolean
    2.         Dim dt As DataTable = DAC.ExecuteDataTable(My.Resources.sp_Update, _
    3.             DAC.Parameter(CN_GoalID, GoalID), _
    4.             DAC.Parameter(CN_Goal, Goal), _
    5.             DAC.Parameter(CN_RowState, EntityState.ToString))
    6.         If EntityState = EntityStateEnum.Added Then
    7.             GoalID = CType(dt.Rows(0).Item(CN_GoalID), Integer)
    8.         End If
    9.         DataStateChanged(EntityStateEnum.Unchanged)
    10.         Return True
    11.     End Function
    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.

  2. #2

    Thread Starter
    New Member
    Join Date
    Apr 2010
    Posts
    4

    Re: Doing Objects in Visual Basic 2005 Project Question

    The error I am getting is 'UPD_Goal' expects parameter '@Goal', which was not supplied, which is why I think the status of my EntityState IF THEN is the key to correcting this. If it helps here is the stored procedure.

    My stored procedure (UPD_Goal) looks like this
    vb Code:
    1. IF @RowState = 'Added'
    2.     BEGIN
    3.         SET NOCOUNT ON;
    4.         INSERT INTO Goals (Goal)
    5.         VALUES  (@Goal)
    6.         SELECT ID = @@Identity
    7.     END

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Doing Objects in Visual Basic 2005 Project Question

    I'm going to guess there's more to the sproc than just that... can you post the whole thing? The bit I'm most interested in is the parameters declaration of the sproc.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    Hyperactive Member
    Join Date
    Apr 2003
    Location
    Three Rivers, MI
    Posts
    354

    Re: Doing Objects in Visual Basic 2005 Project Question

    Please Delete Post. I accidently posted to the wrong thread.
    Last edited by BukHix; Apr 5th, 2010 at 11:47 AM.

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2010
    Posts
    4

    Re: Doing Objects in Visual Basic 2005 Project Question

    Here it is:
    Code:
    ALTER PROCEDURE [dbo].[UPD_Goal]
    (	@GoalID			int			
    	, @Goal			varchar(max)
    	, @RowState		VarChar(50)	
    )
    AS
    IF @RowState = 'Added'
    	BEGIN
    		SET NOCOUNT ON;
    		INSERT INTO Goals (Goal)
    		VALUES 	(@Goal)
    		SELECT ID = @@Identity
    	END
       
    IF @RowState = 'Modified' 
    	BEGIN
    		UPDATE	Goals
    		SET		Goal = @Goal
    		WHERE 	GoalID = @GoalID
    	END
    
    IF @RowState = 'Deleted' 
    	BEGIN
    		Update	Goals Set IsDeleted = 1
    		WHERE	GoalID = @GoalID
    	END
    RETURN

  6. #6

    Thread Starter
    New Member
    Join Date
    Apr 2010
    Posts
    4

    Re: Doing Objects in Visual Basic 2005 Project Question

    Any Ideas?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width