SubQuery in SQL Statement

Posted on 2006-03-23
Last Modified: 2010-04-23
When I run the code below, I get an exception "Specified cast is not valid."

   Dim strSQL As String
   Dim dreader As OleDb.OleDbDataReader
      strSQL = "... some SQL query ..."
      dreader = AccessDBIneraction.GetDataAsDataReader(strSQL)
      While dreader.Read()
         If dreader.GetString(2) = "F" OrElse IsNumeric(dreader.GetString(2)) Then
            strSQL = "... some other SQL query ..."
         End If
      End While
   Catch ex As Exception
      If Not (dreader Is Nothing) Then
         If Not dreader.IsClosed Then
         End If
      End If
   End Try
<code removed per request http:Q_21903646.html>
Question by:GivenRandy
    LVL 69

    Expert Comment

    by:Éric Moreau
    Hi GivenRandy,

    on which line ?

    LVL 9

    Author Comment

    On this line:

             If dreader.GetString(2) = "F" OrElse IsNumeric(dreader.GetString(2)) Then

    In Access, BatesMain and BatesRange are type Number, while NewNumber is type Text.
    LVL 69

    Accepted Solution

    i can't see. place a breakpoint on the line and check the value of dreader.GetString(2). It could be a NULL.
    LVL 9

    Author Comment

    Indeed, it was null. Duh!

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    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…
    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…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    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

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now