create instance of new datarow

Discussion in 'ASP .Net' started by Albert via DotNetMonster.com, Jun 29, 2006.

  1. Hi,

    Let’s say that I have a class (MyRow) that inherits from System.Data.DataRow.


    Is there a way to be able to add a parameter-less constructor and to
    instantiate MyRow as follows:

    class MyRow : System.Data.DataRow
    {
    MyRow(){
    }
    }

    ----
    MyRow r = new MyRow().

    I know the above hardly makes sense but in my case I want to inherit a typed
    row form a typed DataSet.DataTable. Then I could add my own fields in
    addition to the DataColumns already there.

    This sounds suspicious to me, but I post it anyway,

    Thanks in advance

    --
    Message posted via http://www.dotnetmonster.com
     
    Albert via DotNetMonster.com, Jun 29, 2006
    #1
    1. Advertising

  2. sure. you will need to make a class that inherits from the typed dataset,
    that overloads the row create methods if you want to use fill().
    unfortunately you cannot override the indexer without editing the generated
    code.

    alternately, just edit the class file generated by the wizard, and add you
    new properties.

    -- bruce (sqlwork.com)


    "Albert via DotNetMonster.com" <u18435@uwe> wrote in message
    news:6280d94242c24@uwe...
    > Hi,
    >
    > Let's say that I have a class (MyRow) that inherits from
    > System.Data.DataRow.
    >
    >
    > Is there a way to be able to add a parameter-less constructor and to
    > instantiate MyRow as follows:
    >
    > class MyRow : System.Data.DataRow
    > {
    > MyRow(){
    > }
    > }
    >
    > ----
    > MyRow r = new MyRow().
    >
    > I know the above hardly makes sense but in my case I want to inherit a
    > typed
    > row form a typed DataSet.DataTable. Then I could add my own fields in
    > addition to the DataColumns already there.
    >
    > This sounds suspicious to me, but I post it anyway,
    >
    > Thanks in advance
    >
    > --
    > Message posted via http://www.dotnetmonster.com
     
    bruce barker \(sqlwork.com\), Jun 29, 2006
    #2
    1. Advertising

  3. Hi Bruce,

    Once I make a typed DS and include one table I automatically get 2 classes -
    1 for the table and 1 for it's row.
    Then I make a class that inherits from the typed row.

    What I can't do is to overload the typed DataRow base constructor by
    providing a parameter less one.

    It takes only a RowBuilder object as a parameter.

    Can u please provide me with an example of how to overload the DataRow
    constructor to get no params?

    Thanks in advance,
    Albert

    ps. By the way I haven't seen a way for instantiating a DataRow other than:

    DataRow r = MyDataTable.NewRow();

    --
    Albert Benatov
    Skype: abentov
    http://albertbenatov.com

    Message posted via DotNetMonster.com
    http://www.dotnetmonster.com/Uwe/Forums.aspx/asp-net/200606/1
     
    abentov via DotNetMonster.com, Jun 30, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bennett Haselton
    Replies:
    0
    Views:
    687
    Bennett Haselton
    Nov 11, 2004
  2. Sybren Stuvel

    Create new instance of Python class in C

    Sybren Stuvel, Sep 9, 2005, in forum: Python
    Replies:
    5
    Views:
    524
    Sybren Stuvel
    Sep 10, 2005
  3. Sandra-24
    Replies:
    18
    Views:
    1,879
    Steve Holden
    Apr 29, 2006
  4. Rob Dob
    Replies:
    0
    Views:
    474
    Rob Dob
    Sep 28, 2006
  5. Bryan
    Replies:
    5
    Views:
    304
    Bryan
    Oct 23, 2006
Loading...

Share This Page