HELP!!! keep getting "Specified cast is not valid"

Discussion in 'ASP.NET / ASP.NET Core' started by asp_beginner, Oct 3, 2004.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Hi,

    No matter what i tried...i still get the error. I tried using ctype but doesn;t work. Please help!

    Dim arrText As ArrayList = New ArrayList
    Dim arrText1 As ArrayList = New ArrayList 'comment
    Dim mySqlConn As New sqlConn
    Dim SQLConn As SqlConnection = mySqlConn.returnConnection()
    Dim strSQL, strConcatName As String

    strSQL = "select Title,id from tbl_category where Title not in (Select c.Title from tbl_Category c, tbl_usercategory uc, tbl_user u where u.ID=uc.userid and c.id=uc.categoryid and uc.userid=" & intUserID & ")"

    Dim cmd As SqlCommand = New SqlCommand(strSQL, SQLConn)
    SQLConn.Open()

    Dim reader As SqlDataReader = cmd.ExecuteReader()
    Try
    While reader.Read()
    If Not reader.GetValue(0) Is DBNull.Value Then
    arrText.Add(reader.GetString(0).ToString) 'getting title which is in string
    arrText1.Add(reader.GetString(1).ToString) 'getting id which is integer

    End If
    End While

    Finally
    reader.Close()
    SQLConn.Close()
    End Try
     
  2. If you can put that code into a Visual Basic windows forms program and single step through it, that would really help. Then post again and tell us which line is getting the error.

    Also, a great book to buy to help you with data access code is "Programming Visual Basic .NET" by Francesco Balena. You'll love the book.

    Good luck
     
  3. From what I see, if intUserId is an Integer or other numeric data type you need to make it intUserId.ToString in the Sql statement.

    strSQL = "select Title,id from tbl_category where Title not in (Select c.Title from tbl_Category c, tbl_usercategory uc, tbl_user u where u.ID=uc.userid and c.id=uc.categoryid and uc.userid=" & intUserID.ToString & ")"
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page