Passing an object as a Update/InsertParameter

Last post 05-08-2008 8:33 AM by pechar. 3 replies.

Sort Posts:

  • Passing an object as a Update/InsertParameter

    02-26-2007, 5:39 AM
    • Loading...
    • ArmedJimmy
    • Joined on 09-29-2006, 8:07 AM
    • Posts 3

    Hi,

     I'm having a bit of a problem with inserting an Object into my DB from a DetailsView. I've spent quite a bit of time on this and can't get it so I figure I must be doing something stupid.

    I've got a method called for example Insert(MadeUpObject myObject, bool result) which when the user hits "Insert" should be called. I have this selected in my ObjectDataSource as my insert method. It has also populated the insert parameters with the correct parameters for that method:

            <InsertParameters>
                <asp:Parameter Name="myObject" Type="Object" />
                <asp:Parameter Name="result" Type="Object" />
            </InsertParameters>

    However when the user hits "Insert" It gives an exception that says "cannot find a non-generic method with the parameters:" and then it lists myObject,result and then all the properties of MadeUpObject.

     I have gotten around this in the past by creating a new method that takes all the properties of MadeUpObject and then creates an object and passes this to my insert, but I noticed when creating the DataSource it does say you can use a method such as Insert(Product p).

    So any ideas what could be wrong?

     Thanks in advance

    (p.s. I'm using C#)

    http://armedjimmy.blogspot.com
  • Re: Passing an object as a Update/InsertParameter

    02-26-2007, 7:12 AM
    Answer
    • Loading...
    • e_screw
    • Joined on 10-20-2004, 1:22 PM
    • Women, Guitar, Russia, Billiards, Nature, .NET
    • Posts 3,852

    The method signature should be the same as what you are passing in.

    Insert(Object myObject, bool result)
    {
       if (myObject != null)
       {
         MadeUpObject _obj = (MadeUpObject) myObject;
       }
    }

    Try this!

    Thanks

    Mark post(s) as "Answer" that helped you

    Electronic Screw
    Website||Blog||Dub@i.net
  • Re: Passing an object as a Update/InsertParameter

    02-26-2007, 7:13 AM
    Answer
    • Loading...
    • Undying
    • Joined on 10-10-2005, 6:07 AM
    • Posts 68

    The ObjectDataSource require to specify simple Types or a BusinessObject.

    The BO must have a public constructor without arguments.

     If you need some help let me know.

  • Re: Passing an object as a Update/InsertParameter

    05-08-2008, 8:33 AM
    • Loading...
    • pechar
    • Joined on 04-30-2008, 7:51 AM
    • Posts 1

    Undying:

    The ObjectDataSource require to specify simple Types or a BusinessObject.

    The BO must have a public constructor without arguments.

     If you need some help let me know.

    Thanks you saved my day. I've been looking for this for ages.Yes
Page 1 of 1 (4 items)
Microsoft Communities
Page view counter