Solved

vb.net dataset with no results

Posted on 2006-07-19
4
430 Views
Last Modified: 2008-03-06
I have a function to get a dataset from a sql query

    Public Function getDataSet(ByVal selectString As String) As DataSet
        Try
            Dim myData As New DataSet()
            Dim myConnection As New OleDb.OleDbConnection(connectionString)

            myConnection.Open()

            Dim dataAdapter As New OleDb.OleDbDataAdapter(selectString, myConnection)

            dataAdapter.Fill(myData)

            getDataSet = myData

        Catch ex As Exception

            MsgBox("Database Error")
            getDataSet = Nothing

        End Try

    End Function

I am coming from vb6.  I used to see if the recordset = eof if there were no results.

What would the vb.net equivalent with a dataset be?
0
Comment
Question by:jackjohnson44
[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
4 Comments
 
LVL 24

Accepted Solution

by:
Jeff Certain earned 400 total points
ID: 17138545
You can get away with using a dataTable instead of a dataset. However, if you're using a dataset, you need to check to see if table 0 of the dataset has any rows.

If myData.Tables.Count = 0 orelse MyData.Tables(0).Rows.Count = 0 Then
' No data retrieved
End If
0
 

Author Comment

by:jackjohnson44
ID: 17138558
thanks, will either work, or do I need them both?
0
 
LVL 17

Assisted Solution

by:ZeonFlash
ZeonFlash earned 100 total points
ID: 17139160
You'd need both, because using .Tables.Count = 0 won't tell you if you have rows, and .Tables(0).Rows.Count = 0 runs the risk of referencing a table that doesn't exist.
0
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 17139181
Exactly... which is why I included both... and the OrElse is important to shortcircuit the second half of the statement. (i.e. the rowcount doesn't get checked if the table doesn't exist)
0

Featured Post

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

617 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