?
Solved

Check if DataAdapter holds rows

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

752 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