Solved

Check if DataAdapter holds rows

Posted on 2009-04-02
4
458 Views
Last Modified: 2012-06-21
Hi EE,

I am trying to figure out how to tell if a dataadapter has rows.  I know how to do it with a datareader, but haven't been able to figure out how with a dataadapter.
Please provide an example.  Clicking on links crash my IE.
Below is the code I use to fill the dataadapter.
Thanks
Dim ds As New DataSet
 

        If DatabaseToUse() = BizObjs.DBType.Access Then

            'Access Database
 
 

            Dim dc As New OleDb.OleDbConnection(ConnectionString)

            Dim da As New OleDb.OleDbDataAdapter(SelectStatement, dc)
 

            Try
 

                da.Fill(ds)

                dc.Close()

                da.Dispose()
 

            Catch ex As Exception

                dc.Close()

                'Throw ex
 

            End Try

        End If
 

        Return GenerateDataTable(ds)

Open in new window

0
Comment
Question by:Sheritlw
  • 2
  • 2
4 Comments
 
LVL 4

Expert Comment

by:y0usuf
ID: 24055598
You can use ds.tables(0).rows.count.
check
if ds.tables(0).rows.count>0 then

 ' Block Of Code

End If


Please let me know if I am not following your question correctly.
0
 

Author Comment

by:Sheritlw
ID: 24055674
How does the dataset know what is in there since the fill will go after the "if ds.tables(0).rows.count>0 then".  There is no other reference to the dataset until then?
Thanks
0
 
LVL 4

Accepted Solution

by:
y0usuf earned 500 total points
ID: 24055915
Where are you getting the exception in your code? I am guessing it is not when you fill the dataset. You need to check for the row count before you use the dataset( You need to fill the dataset and then check for row count before using it).
0
 

Author Comment

by:Sheritlw
ID: 24057346
I was getting the error right on the da.fill(ds).  I just tried again and I no longer get the error.  Not sure what is going on, but thanks for your help
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now