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

SubQuery in SQL Statement

When I run the code below, I get an exception "Specified cast is not valid."

---
   Dim strSQL As String
   Dim dreader As OleDb.OleDbDataReader
   
   Try
      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 ..."
            AccessDBIneraction.ExecuteNonQuery(strSQL)
         End If
      End While
   
   Catch ex As Exception
      MessageBox.Show(ex.Message)
   
   Finally
      If Not (dreader Is Nothing) Then
         If Not dreader.IsClosed Then
            dreader.Close()
            AccessDBIneraction.CloseConnection()
         End If
      End If
   End Try
---
<code removed per request http:Q_21903646.html>
0
GivenRandy
Asked:
GivenRandy
  • 2
  • 2
1 Solution
 
Éric MoreauSenior .Net ConsultantCommented:
Hi GivenRandy,

on which line ?

Cheers!
0
 
GivenRandyAuthor Commented:
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.
0
 
Éric MoreauSenior .Net ConsultantCommented:
i can't see. place a breakpoint on the line and check the value of dreader.GetString(2). It could be a NULL.
0
 
GivenRandyAuthor Commented:
Indeed, it was null. Duh!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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