Solved

Check if DataAdapter holds rows

Posted on 2009-04-02
4
455 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 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

10 Experts available now in Live!

Get 1:1 Help Now