Home All Groups Group Topic Archive Search About

Null returns from DataAdapter.Fill()

Author
5 Jan 2005 7:44 PM
Michael Kellogg
I'm populating a DataTable using a DataAdapter.Fill() statement.  It works
just fine as long as the return is successful.  However, when my query
returns no rows, rather than getting a "0" for rows returned (the function
is supposed to return an integer), I get a "System.ArgumentNullException"
apparently because there is nothing to populate the DataTable with.

How can I trap for this without resorting to exception handling?

TIA

Michael
Author
5 Jan 2005 8:00 PM
W.G. Ryan eMVP
How are you checking it?  You can use Rows.Count ie
return (DataSetName != null) ? DataSetName.TableName.Rows.Count : 0;

Show quoteHide quote
"Michael Kellogg" <mkell***@WEDELIVERcc3.com> wrote in message
news:Xns95D5782FB90D2mkelloggWEDELIVERcc3@207.46.248.16...
> I'm populating a DataTable using a DataAdapter.Fill() statement.  It works
> just fine as long as the return is successful.  However, when my query
> returns no rows, rather than getting a "0" for rows returned (the function
> is supposed to return an integer), I get a "System.ArgumentNullException"
> apparently because there is nothing to populate the DataTable with.
>
> How can I trap for this without resorting to exception handling?
>
> TIA
>
> Michael
Are all your drivers up to date? click for free checkup

Author
5 Jan 2005 9:24 PM
Miha Markic [MVP C#]
Hi Michael,

It shouldn't crash like that.
What provider are you using?
Can you show us the piece of code that causes this behaviour?

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
SLODUG - Slovene Developer Users Group
www.rthand.com

Show quoteHide quote
"Michael Kellogg" <mkell***@WEDELIVERcc3.com> wrote in message
news:Xns95D5782FB90D2mkelloggWEDELIVERcc3@207.46.248.16...
> I'm populating a DataTable using a DataAdapter.Fill() statement.  It works
> just fine as long as the return is successful.  However, when my query
> returns no rows, rather than getting a "0" for rows returned (the function
> is supposed to return an integer), I get a "System.ArgumentNullException"
> apparently because there is nothing to populate the DataTable with.
>
> How can I trap for this without resorting to exception handling?
>
> TIA
>
> Michael
Author
5 Jan 2005 10:19 PM
Sahil Malik
Usually you get that error/exception if you pass in a null/nothing dataset
to dataadapter.fill.
Other than that, did you see this KB article -
http://support.microsoft.com/kb/313028/EN-US/ <-- maybe that'll help.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik



Show quoteHide quote
"Michael Kellogg" <mkell***@WEDELIVERcc3.com> wrote in message
news:Xns95D5782FB90D2mkelloggWEDELIVERcc3@207.46.248.16...
> I'm populating a DataTable using a DataAdapter.Fill() statement.  It works
> just fine as long as the return is successful.  However, when my query
> returns no rows, rather than getting a "0" for rows returned (the function
> is supposed to return an integer), I get a "System.ArgumentNullException"
> apparently because there is nothing to populate the DataTable with.
>
> How can I trap for this without resorting to exception handling?
>
> TIA
>
> Michael
Author
19 May 2005 10:25 PM
Luis
Hi Michael
I have the same problem on having populated the DATASET.
Sending departs from the code in order that they could help us.


                    sqldaCliente.Fill(dsReporte, "CUS")
                    sqldaRegVent.Fill(dsReporte, "IMS_RegVtas")

They are related tables and on having populated with the DATAADAPTER.FILL

return message  error:  VALUE CANNOT BE NULL

Thank you for hishelp

Luis.


Show quoteHide quote
"Michael Kellogg" wrote:

> I'm populating a DataTable using a DataAdapter.Fill() statement.  It works
> just fine as long as the return is successful.  However, when my query
> returns no rows, rather than getting a "0" for rows returned (the function
> is supposed to return an integer), I get a "System.ArgumentNullException"
> apparently because there is nothing to populate the DataTable with.
>
> How can I trap for this without resorting to exception handling?
>
> TIA
>
> Michael
>

Bookmark and Share