Reading from DataSet using EXCEL data

Posted on 2006-04-21
Last Modified: 2012-05-05
       Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=" & Session("fn") & ";" & _
        "Extended Properties=""Excel 8.0;HDR=No;IMEX=1"""

        Dim myData As New OleDbDataAdapter("SELECT F1 FROM [Sheet1$]", strConn)
        myData.TableMappings.Add("Table", "ExcelTest")
        Dim myDataset As New DataSet
        myData.Fill(myDataset, "table1")
        Dim emailStr As String

        For Each Dr As DataRow In myDataset.Tables(0).Rows       <<<<<<<
            emailStr = Dr(0)
            mailObj.To = emailStr

the problem is when it reaches the first blank row, then gives the message:

"Cast from type 'DBNull' to type 'String' is not valid."

it seems to read in the blank rows instead of stopping. How can I get it to stop
when it hits the first blank row? thanks

Question by:MikeMCSD
    LVL 6

    Accepted Solution

    Try This:

    Imports System.DBNull
    For Each Dr As DataRow In myDataset.Tables(0).Rows       <<<<<<<
         If Dr(0) Is System.DBNull.Value Then
              <<<< dO sOMETHING >>>>
         End If
    LVL 16

    Author Comment

    did the trick . . thanks JR

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Introduction When many people think of the WebBrowser ( control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    732 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

    19 Experts available now in Live!

    Get 1:1 Help Now