|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Null returns from DataAdapter.Fill()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 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 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? -- Show quoteHide quoteMiha Markic [MVP C#] - RightHand .NET consulting & development SLODUG - Slovene Developer Users Group www.rthand.com "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 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 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 >
Other interesting topics
DBnull, Date and DataAdapter
Bulk Insert Via SQLCommand? GetChildRows - Finding Deleted ChildRows ? Constraint violated but no exception thrown Problem with Update Adapter Really need some help on this Thread was being aborted Errors Handling very huge data typed dataset and sort order on save How can I read a list of files from a folder into a DataTable? |
|||||||||||||||||||||||