• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 242
  • Last Modified:

Reading from DataSet using EXCEL data

       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


0
MikeMCSD
Asked:
MikeMCSD
1 Solution
 
JRossi1Commented:
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
nEXT
0
 
MikeMCSDAuthor Commented:
did the trick . . thanks JR
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now