views:

290

answers:

1

I have a business object that I've been using, which has a bunch of properties and a Save method, which inserts/updates to the database. The save method is NOT status, so the object needs to be instantiated, and the properties for the DB update/insert get pulled from the object.

Now I'm trying to bind the object to a FormView with the ObjectDataSource. I have it working so it instantiates based on the QueryString parameter, no problem, and populates the textboxes just fine. The UpdateMethod I have set to the Save function. Now it gets stuck.

It seems the ObjectDataSource needs a method with all the fields/properties/textboxes as parameters. I would have thought it would update the object's properties and then call the parameterless Save function. Is this wishful thinking?

Do I now need to change my Save function to include parameters, and change all the instances where it's getting used to this new method, just for this reason?

Thanks Sean

+1  A: 

Unfortunatly it does require params.

I overloaded my insert/update methods to include a few params. Attach the ObjectDataSource to the method with params.

The overloaded Update method calls the original Update method saving all the data. Seems kind of hackish to me, but it works.

        Public Sub Update()
        Dim isUpdated As Boolean = False

        sql = "UPDATE AudioFiles SET Title = @Title, [desc] = @desc, Active = @Active WHERE fileID = @fileID"
        conn = New SqlConnection(connString)
        conn.Open()

        ...

    End Sub

    Public Sub Update(ByVal upFileID As Integer, ByVal upTitle As String, ByVal upDesc As String, ByVal upActive As Boolean)
        Dim isUpdated As Boolean = False
        Dim audioFile As New AudioFiles(fileID)

        If Len(upTitle) > 0 Then
            _title = title
        End If

        ...  

       audioFile.Update()

    End Sub
Gthompson83