Typed DataSets and casing problems
-
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 -
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.comI'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
-
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
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