Solved

vb.net dataset with no results

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Telerik RadEditor Control Save 8 39
Create simple VB.net Add-in for Excel in Office 365 2 57
Open telerik datetime picker programmatically 13 42
Adding Rows to Grid 4 32
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 …
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

734 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