Solved

vb.net dataset with no results

Posted on 2006-07-19
4
415 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

867 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

26 Experts available now in Live!

Get 1:1 Help Now