Cannot convert type 'object[]' to 'System.Data.DataRow'

Discussion in 'ASP .Net' started by Paulo, May 27, 2008.

  1. Paulo

    Paulo Guest

    DataRow dr = (DataRow)ds.Tables[0].Rows[1].ItemArray;

    Error 1 Cannot convert type 'object[]' to 'System.Data.DataRow' C:\Documents
    and Settings\Fabio\Meus documentos\Visual Studio
    2005\Projects\CodBarraPalm\CodBarraPalm\Default.aspx.cs 35 26 CodBarraPalm
    ?

    why this error trying to get the contents of a row on a DataSet?
     
    Paulo, May 27, 2008
    #1
    1. Advertising

  2. if you want a single row just use

    DataRow dr = ds.Tables[0].Rows[1];


    --
    Misbah Arefin
    https://mcp.support.microsoft.com/profile/MISBAH.AREFIN
    http://dotnethitman.spaces.live.com
    http://www.linkedin.com/in/misbaharefin




    "Paulo" <> wrote in message
    news:...
    > DataRow dr = (DataRow)ds.Tables[0].Rows[1].ItemArray;
    >
    > Error 1 Cannot convert type 'object[]' to 'System.Data.DataRow'
    > C:\Documents and Settings\Fabio\Meus documentos\Visual Studio
    > 2005\Projects\CodBarraPalm\CodBarraPalm\Default.aspx.cs 35 26 CodBarraPalm
    > ?
    >
    > why this error trying to get the contents of a row on a DataSet?
    >
    >
     
    Misbah Arefin, May 27, 2008
    #2
    1. Advertising

  3. Paulo

    Norm Guest

    On May 27, 11:45 am, "Paulo" <> wrote:
    > DataRow dr = (DataRow)ds.Tables[0].Rows[1].ItemArray;
    >
    > Error 1 Cannot convert type 'object[]' to 'System.Data.DataRow' C:\Documents
    > and Settings\Fabio\Meus documentos\Visual Studio
    > 2005\Projects\CodBarraPalm\CodBarraPalm\Default.aspx.cs 35 26 CodBarraPalm
    > ?
    >
    > why this error trying to get the contents of a row on a DataSet?


    This error is because you are refering to the ItemArray. ItemArray
    returns an array of objects that contains the values of each column in
    the DataRow by ordinal. Simply remove the ".ItemArray" and that will
    work.

    DataRow dr = (DataRow)ds.Tables[0].Rows[1];

    In the future, you might want to actually look at the error
    description. It specifically says that it can't convert an array of
    objects "object[]" to a DataRow.
    Happy coding!
     
    Norm, May 27, 2008
    #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. Paul W
    Replies:
    1
    Views:
    1,381
    Bryant Hankins
    Aug 6, 2004
  2. Patrick Olurotimi Ige
    Replies:
    3
    Views:
    8,921
    Patrick Olurotimi Ige
    May 4, 2005
  3. Eugene Anthony

    System.Data.DataRow error

    Eugene Anthony, Feb 7, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    592
    =?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=
    Feb 7, 2007
  4. Robert
    Replies:
    5
    Views:
    995
    阿利
    Apr 20, 2006
  5. john harkin
    Replies:
    1
    Views:
    866
    john harkin
    Sep 23, 2004
Loading...

Share This Page