PDA

View Full Version : HELP!!! keep getting "Specified cast is not valid"


asp_beginner
10-03-2004, 09:40 AM
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

RNEAST
10-08-2004, 10:34 AM
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

tourneymanagerpro
10-08-2004, 12:21 PM
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 & ")"