Hi,
The error you posted is not indicating to me that you have a null or "empty"
DataRow - it's indicating that the DataRow is not what you expect it to be.
Quote:
myCRUDXHelper.GetRowBy();
I know that myCRUDXHelper is filling a DataTable (or DataSet) and returning a
single DataRow. I know this because DataRow doesn't supply a public
constructor.
I assumed that drSplitsToUse was generated as follows:
DataRow drSplitsToUse = SomeObj.GetManualDailySplits(id, type, dateTime)
Quote:
decimal.Parse(drSplitsToUse["PercentSat"].ToString());
If the above line throws the following error
Quote:
"Column 'PercentSat' does not belong to table IsNull."
then I must assume that it's being thrown in the following part:
Quote:
drSplitsToUse["PercentSat"]
and that the following line contains buggy code because it's producing the
DataRow that has no "PercentStat" column defined:
Quote:
myCRUDXHelper.GetRowBy();
You expect a column named, "PercentStat", but the DataRow you are checking
doesn't have one.
The error indicates that the name of the DataTable is, "IsNull". IsNull is a
T-SQL function. It's also a function supported in "expressions" in the
context of DataSets. Also, it's a method on DataRow. It's just a really
strange name for a DataTable and so I assume you got some bugs in your dynamic
DAL code.
Quote:
The stored procedure then returns an "empty" DataRow
"Empty" doesn't usually mean "no schema", but that's what I suspect is
happening here and your DAL can't handle it.
In your stored procedure, make sure that at least the schema is returned even
if no rows are because if you're not using a strong-typed DataSet then you
would get the error that you are getting. You can do this quite easily:
IF NOT EXISTS(...)
SELECT * FROM TheTable WHERE ...
ELSE -- I'm guessing that you have the "IF" but no "ELSE"
SELECT TOP 0 * FROM TheTable
You should fix the DAL, the stored proc or both, depending on which is buggy.
You will probably want the DAL's GetRowBy() method to return a null reference
when no records are returned in a result set instead of a corrupt DataRow.
Then, check the result for null before attempting to use it in code (as Peter
suggested in a different post in this thread).
GL
--
Dave Sexton
"mcbobin" <mcbobin@gmail.comwrote in message
news:1162412717.057963.230860@f16g2000cwb.googlegr oups.com...
Quote:
Thanks for keeping on looking Dave!
>
Sorry for the delay in replying, I left work at after my previous post
as I was getting too frustrated to concentrate...
>
I think my problem is that I'm not first creating a DataTable and then
extracting a DataRow from it - I'm only creating the DataRow itself.
This means that when the stored procedure returns an empty table (i.e.
the store has never entered any manual daily splits), the DataRow
object that is then returned (from the GetManualDailySplits method
described in my first post) cannot be used in any meaningful way.
>
I think I'll just create a DataTable and count the number of
rows...then have a word with the chap who sorted out the DAL and see
what he can do.
>
Thanks again
>