Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

vb.net dataset with no results

Posted on 2006-07-19
4
Medium Priority
?
451 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 1600 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 400 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

972 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