473,395 Members | 1,668 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to determine if dataset is empty?

Hi folks... .NET newbie I admit. I'm running VS 2005 version 8 on .NET platform 2.0.50727 SP1. How can you tell if a query has returned an empty dataset to a SQLReader or a DataTable? I am running this code...
Dim cnnNav3 As SqlConnection = New SqlConnection("Data Source _
& =(local);initial catalog=NAVSQL;Integrated Security = SSPI")
cnnNav3.Open()
Dim strYarn As String
strYarn = cy(j, 0) 'from a previous array
Dim cmdYarnPrice As SqlCommand = cnnNav3.CreateCommand
cmdYarnPrice.CommandType = CommandType.Text
cmdYarnPrice.CommandText = "Select [Standard Cost] from" _
& "Item where [Item No.] = '" & strItem & "'"
Dim daYarnPrice As SqlDataAdapter = New SqlDataAdapter()
daYarnPrice.SelectCommand = cmdYarnPrice
daYarnPrice.Fill(ds, "Item")
Dim dtYarnPrice As DataTable
dtYarnPrice = ds.Tables("Item")
Up to this point the code seems to run fine, but if I try to say..
if dtYarnPrice.rows.count > 0
I get an error. Debug tells me that dtYarnPrice equals Nothing, so evidently no records were returned, but .NET rejects any expressions like...
if dtYarnPrice = Nothing then
So how do I determine whether my query returned any rows?? Thanks in advance for your time...


Chandler
Jan 24 '08 #1
2 1566
dip_developer
648 Expert 512MB
Hi folks... .NET newbie I admit. I'm running VS 2005 version 8 on .NET platform 2.0.50727 SP1. How can you tell if a query has returned an empty dataset to a SQLReader or a DataTable? I am running this code...

Dim cnnNav3 As SqlConnection = New SqlConnection("Data Source _

& =(local);initial catalog=NAVSQL;Integrated Security = SSPI")
cnnNav3.Open()
Dim strYarn As String
strYarn = cy(j, 0) 'from a previous array
Dim cmdYarnPrice As SqlCommand = cnnNav3.CreateCommand
cmdYarnPrice.CommandType = CommandType.Text
cmdYarnPrice.CommandText = "Select [Standard Cost] from" _
& "Item where [Item No.] = '" & strItem & "'"
Dim daYarnPrice As SqlDataAdapter = New SqlDataAdapter()
daYarnPrice.SelectCommand = cmdYarnPrice
daYarnPrice.Fill(ds, "Item")
Dim dtYarnPrice As DataTable
dtYarnPrice = ds.Tables("Item")
Up to this point the code seems to run fine, but if I try to say..

if dtYarnPrice.rows.count > 0
I get an error. Debug tells me that dtYarnPrice equals Nothing, so evidently no records were returned, but .NET rejects any expressions like...

if dtYarnPrice = Nothing then
So how do I determine whether my query returned any rows?? Thanks in advance for your time...


Chandler
try............ ds.Tables[0].Rows.Count
Jan 24 '08 #2
try............ ds.Tables[0].Rows.Count

Thank you! That did the trick, and I even see how it works.

Chandler
Jan 24 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: atse | last post by:
Hi, I still don't know how to determine a empty folder. Can you tell me more detail? thanks Atse "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message...
2
by: Andreas Palm | last post by:
I have a dataset that has DBNull in certain columns, now when I write out this one to XML, I only get the columns as elements that do have data in it. However I do need also the empty colums as...
2
by: Sam | last post by:
Hi all. I have a XSD file and a flat file (txt). My customer want that I create a XML (with XSD + file data). OK. 1) I open visual studio 2) I create a typed dataset (read xsd schema) 3) Now, I...
0
by: Jan Schustr | last post by:
I have dataGrid and as datasource is dataSet.Table . In my app i set datasource to dataset.tables , in this moment is dataset empty. Then user click on the button, run another (long-during) thread,...
3
by: martin | last post by:
Hi, I am having trouble determining if my dataset is empty. I have function that populates a dataset from a database and then retuens it. If the database contains no data then the dataset will...
8
by: Marcel Hug | last post by:
Hi all ! I have datas in a dataset. I would like to save them in a new table (just created). Do I have to run trought all recordsets with an Insert into statement ? (it takes very long) Thanks
4
by: Amit Maheshwari | last post by:
I need to read text file having data either comma seperated or tab seperated or any custom seperator and convert into a DataSet in C# . I tried Microsoft Text Driver and Microsoft.Jet.OLEDB.4.0...
6
by: WestAussie | last post by:
Hello I'm using Visual Studio 2005 and Microsoft Access 2007 (database is saved in 2007 format). The code which I have been using to display data in a DataGridView from a stored procedure in...
3
by: dbuchanan | last post by:
How, at rundime, do I capture the fact that the parametrized query that fills a CheckBoxList results in an empty set. When the dataset is empty the CheckBoxList does not appear. I would like to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.