Cast from type 'Field' to type 'Integer' is not valid

W

William Mild

I am porting old Dreamweaver generated ASP code to
ASP.NET (VBScript to VB.NET).
Error: Cast from type 'Field' to type 'Integer' is not
valid
The error occurs on the line which says "rsStudents =
Server.CreateObject("ADODB.Recordset")".


if (Request.QueryString("StudentID") <> "") then
rsStudents__MMColParam = Request.QueryString("StudentID")

Dim rsStudents
rsStudents = Server.CreateObject("ADODB.Recordset")
rsStudents.ActiveConnection = MM_cnReportCards_STRING
rsStudents.Source = "SELECT * FROM dbo.Student WHERE
StudentID = " & Replace
(rsStudents__MMColParam, "'", "''") & ""
rsStudents.CursorType = 0
rsStudents.CursorLocation = 2
rsStudents.LockType = 3
rsStudents.Open()
Dim rsStudents_numRows As Integer = 0

Any ideas, besides rewriting the whole thing using a
datareader?
 
W

William Mild

Hi Armin. Before I posted this, I said to myself. "Ok,
self. Now check that code and make sure there isn't
a .Value that you missed! And I checked it, but I can't
find a .Value that I missed." But thanks for the
suggestion.
 
W

William Mild

Found the bug. And I think there is some kind of bug in
the VS.NET debugger. It was a missing ".Value" but the
debugger gave wrong line number. I had an include file
where the the ".Value" was missing. I found it by moving
a "respond.end" through the code until an error
generated. Eventually, I was putting the "respond.end"
into the include file until I saw the missing ".Value".
The strange thing is that, when I tried to reproduce the
bug by taking out the ".Value," the error page produced
the correct error. So, I can't pass this one on the
Microsoft for review.
 
A

Armin Zingler

William Mild said:
Hi Armin. Before I posted this, I said to myself. "Ok,
self. Now check that code and make sure there isn't
a .Value that you missed! And I checked it, but I can't
find a .Value that I missed." But thanks for the
suggestion.

Hmm.... Is this the VB.NET code? Did you enable Option Strict?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top