Solved

vb.net dataset with no results

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
WPF issue with Trigger 2 69
Convert to Hour/minute textbox and compare 3 36
VB.NET HttpWebRequest 12 34
Events in static methods 3 31
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

13 Experts available now in Live!

Get 1:1 Help Now