[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Check if DataAdapter holds rows

Posted on 2009-04-02
4
Medium Priority
?
486 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 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month18 days, 7 hours left to enroll

830 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