|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How do you test for an empty datasetby a user and returns a dataset with all related data found in a database. In my client app use this code to get the data from the web service : Dataset dsData = ws.wsmethod(parameter); And whether any data is returned or not, I don't get an error, so I need to test if the dataset is empty or not to see if any data has been returned. Can anybody help me out with this? Cheers, Mike *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! Mike, question 1 is whether the returned dataset reference can be null. If
so, you need to check for that first. If not, then be aware that a DataSet contains a collection of DataTable objects. For each DataTable object, you can access the Rows collection and check its Count property. Show quote "Mike P" <mike.p***@gmail.com> wrote in message news:ejH9vyUMFHA.732@TK2MSFTNGP12.phx.gbl... >I have written a simple web service that basically takes a value input > by a user and returns a dataset with all related data found in a > database. > > In my client app use this code to get the data from the web service : > > Dataset dsData = ws.wsmethod(parameter); > > And whether any data is returned or not, I don't get an error, so I need > to test if the dataset is empty or not to see if any data has been > returned. > > Can anybody help me out with this? > > > Cheers, > > Mike > > > > *** Sent via Developersdex http://www.developersdex.com *** > Don't just participate in USENET...get rewarded for it! JV,
Using if (ds == null) doesn't seem to work, so I'm having to use this syntax to check if the Dataset is empty or not : string str = dsTransResult.Tables["tbl"].Rows.Count.ToString(); Is this the standard way of doing this, it seems a bit long winded just to check for an empty dataset? Cheers, Mike *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! You got it right. (Although not sure that the ToString() is for in this
context.) You could always wrap this in some utility/helper method. Show quote "Mike P" <mike.p***@gmail.com> wrote in message news:OBRQaNVMFHA.732@TK2MSFTNGP12.phx.gbl... > JV, > > Using if (ds == null) doesn't seem to work, so I'm having to use this > syntax to check if the Dataset is empty or not : > > string str = dsTransResult.Tables["tbl"].Rows.Count.ToString(); > > Is this the standard way of doing this, it seems a bit long winded just > to check for an empty dataset? > > > Cheers, > > Mike > > > > *** Sent via Developersdex http://www.developersdex.com *** > Don't just participate in USENET...get rewarded for it!
Show quote
"Peter Rilling" <peter@nospam.rilling.net> wrote in message Do you need to go that far, can't you just test the dataset's Tables.Count? Or news:ePJfwTVMFHA.3352@TK2MSFTNGP10.phx.gbl... > You got it right. (Although not sure that the ToString() is for in this > context.) > > You could always wrap this in some utility/helper method. > > "Mike P" <mike.p***@gmail.com> wrote in message > news:OBRQaNVMFHA.732@TK2MSFTNGP12.phx.gbl... >> JV, >> >> Using if (ds == null) doesn't seem to work, so I'm having to use this >> syntax to check if the Dataset is empty or not : >> >> string str = dsTransResult.Tables["tbl"].Rows.Count.ToString(); >> >> Is this the standard way of doing this, it seems a bit long winded just >> to check for an empty dataset? >> >> >> Cheers, >> >> Mike >> might it have tables that are present but of no use? -- Joe (MVP) https://mvp.support.microsoft.com/profile=8AA9D5F5-E1C2-44C7-BCE8-8741D22D17A5 Joe Fawcett wrote:
Show quote > "Peter Rilling" <peter@nospam.rilling.net> wrote in message Tables.Count counts the number of "tables". There probably is at least > news:ePJfwTVMFHA.3352@TK2MSFTNGP10.phx.gbl... > >>You got it right. (Although not sure that the ToString() is for in this >>context.) >> >>You could always wrap this in some utility/helper method. >> >>"Mike P" <mike.p***@gmail.com> wrote in message >>news:OBRQaNVMFHA.732@TK2MSFTNGP12.phx.gbl... >> >>>JV, >>> >>>Using if (ds == null) doesn't seem to work, so I'm having to use this >>>syntax to check if the Dataset is empty or not : >>> >>>string str = dsTransResult.Tables["tbl"].Rows.Count.ToString(); >>> >>>Is this the standard way of doing this, it seems a bit long winded just >>>to check for an empty dataset? >>> >>> >>>Cheers, >>> >>>Mike >>> > > Do you need to go that far, can't you just test the dataset's Tables.Count? Or > might it have tables that are present but of no use? > one table, but that might be empty. Tables[0].Rows.Count counts the number of actual rows in the first table (and ignores any other tables that might be present). -- Hans Kesting if you are looking to see if the Data set object is empty ie null or has no
tables, then ds.Tables["my table name "] with throw an exception if "my table name" is not in your data set. So what you need to do is check if ds is null, then see if the ds.Tables.count >0, see if it has your table ds.Tables.Contains("my table name"), now you can look at the table and see if it has any rows ds.Tables["my table name"].Rows.Count >0 Aaron Show quote "Mike P" wrote: > JV, > > Using if (ds == null) doesn't seem to work, so I'm having to use this > syntax to check if the Dataset is empty or not : > > string str = dsTransResult.Tables["tbl"].Rows.Count.ToString(); > > Is this the standard way of doing this, it seems a bit long winded just > to check for an empty dataset? > > > Cheers, > > Mike > > > > *** Sent via Developersdex http://www.developersdex.com *** > Don't just participate in USENET...get rewarded for it! > |
|||||||||||||||||||||||