Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Typed DataSets and casing problems

Typed DataSets and casing problems

Scheduled Pinned Locked Moved C#
comhelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Andrew Connell
    wrote on last edited by
    #1

    I've created a strongly typed dataset but whenever I try to select rows from a table and try to cast the rows, I'm getting an error "Specified cast is not valid.". I have a table named "Inventory". I'm able to select rows and place them in a variable with type DataRow[]. However, when I try to cast it to a InventoryRow, I get errors every time. Here's the code: my dataset name is PADS... working code: DataRow[] recordArray = this._dataSet.Inventory.Select(); error code: PADS.InventoryRow[] recordArray = (PADS.InventoryRow[])this._dataSet.Inventory.Select(); I'm certain I'm using the correct variable names because I'm able to easily create new records with the following: PADS.InventoryRow record = this._dataSet.Inventory.NewInventoryRow(); this._dataSet.Inventory.AddInventoryRow(record); Any input would be greatly appreciated! Andrew Connell, MCDBA IM on MSN andrew@aconnell.com

    J 1 Reply Last reply
    0
    • A Andrew Connell

      I've created a strongly typed dataset but whenever I try to select rows from a table and try to cast the rows, I'm getting an error "Specified cast is not valid.". I have a table named "Inventory". I'm able to select rows and place them in a variable with type DataRow[]. However, when I try to cast it to a InventoryRow, I get errors every time. Here's the code: my dataset name is PADS... working code: DataRow[] recordArray = this._dataSet.Inventory.Select(); error code: PADS.InventoryRow[] recordArray = (PADS.InventoryRow[])this._dataSet.Inventory.Select(); I'm certain I'm using the correct variable names because I'm able to easily create new records with the following: PADS.InventoryRow record = this._dataSet.Inventory.NewInventoryRow(); this._dataSet.Inventory.AddInventoryRow(record); Any input would be greatly appreciated! Andrew Connell, MCDBA IM on MSN andrew@aconnell.com

      J Offline
      J Offline
      jparsons
      wrote on last edited by
      #2

      I've run into a problem like this before with a server i wrote. I couldn't find any elegant solution. Logic tells you that you should be able to make this class but for some reason it won't allow it. What I ended up doing was creating an Array of the more specific type ( PADS.InventoryRow ) and then manually putting every element from the array returned from select into the more sepcific array. If you find an easier way to od that please post it. Jared jparsons@jparsons.org www.prism.gatech.edu/~gte477n

      A 1 Reply Last reply
      0
      • J jparsons

        I've run into a problem like this before with a server i wrote. I couldn't find any elegant solution. Logic tells you that you should be able to make this class but for some reason it won't allow it. What I ended up doing was creating an Array of the more specific type ( PADS.InventoryRow ) and then manually putting every element from the array returned from select into the more sepcific array. If you find an easier way to od that please post it. Jared jparsons@jparsons.org www.prism.gatech.edu/~gte477n

        A Offline
        A Offline
        Andrew Connell
        wrote on last edited by
        #3

        Yikes!:eek: That's something I definatley don't want to get into. I'd much rather deal with the native DataRow objects than manually add each item into the typed object. That seems like a TON of overhead. If I find anything I'll be sure to post it. In the meantime, I'm investigating MAPPING and merging the two different types. If I can do that in my data access layer/components, and just continue on with the application development, then I'm fine with that. Andrew Connell, MCDBA IM on MSN andrew@aconnell.com

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups