Solved

Check if DataAdapter holds rows

Posted on 2009-04-02
4
468 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

730 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