Wrox Programmer Forums
|
VB.NET General VB.NET discussions for issues that don't fall into other VB.NET forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 30th, 2003, 01:53 PM
Authorized User
 
Join Date: Aug 2003
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dataset Contains Data?

I'm using VB.NET (not 2003) and want to know how I can determine whether or not a dataset I've created actually HAS any data in it. I know in 2003, you can use the .hasrows function, but I'm not sure how to do this in the first version.
I ask because I have several query possibilites a user can select. From the query, the results are populated in a datagrid. If there aren't any results in the grid, I want to tell the user that no results were found..not just that for some reason the grid didn't populate.

ANY help would be appreciated.

 
Old December 30th, 2003, 02:56 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

You can check the Count property of the Rows collection of the DataTable you're interested in:

If (MyDataSet.Tables("MyTable").Rows.Count > 0)
  ' Has Data
Else
  ' No Records
End If

AFAIK, the HasRows only applies to a DataReader and not to a DataSet. Were you referring to a DataReader?

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old December 30th, 2003, 02:59 PM
Authorized User
 
Join Date: Aug 2003
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks. I'll try that! ;)

 
Old December 30th, 2003, 03:10 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

But were you talking about a DataReader or a DataSet?

With a Reader, you can't use the code I showed you. Instead, you should bind your data to your control (a Repeater, a DataGrid, etc) and then check its Item.Count property:

If DataGrid1.Items.Count > 0 Then
  ' Data
Else
  ' No Data
  ' DataGrid1.Visible = False
  ' lblNoRecords.Visible = True
End If

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old January 29th, 2004, 02:58 PM
Registered User
 
Join Date: Jan 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a ton, that just bailed me out.






Similar Threads
Thread Thread Starter Forum Replies Last Post
how to format data on dataset bishnupokhrel ASP.NET 2.0 Professional 0 March 21st, 2007 03:23 AM
Sorting data in a DataSet pbyrum ADO.NET 5 May 18th, 2006 05:11 PM
DataSet data busybee ASP.NET 1.0 and 1.1 Basics 0 April 3rd, 2006 05:55 AM
Data from dataset bubljo ADO.NET 3 October 26th, 2004 08:02 AM
DataSet & data melvik ADO.NET 6 April 28th, 2004 07:58 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.