0

I am trying to extract one integer from the database but am getting errors

My code in the controller is:

        Dim SeqNumQuery = From a In db.RequestedServices
                          Where a.RequestedServiceId = id
                          Select a.StationId

        Dim StationId As Integer = SeqNumQuery.ToString

And error is:

Range variable 'StationId' hides a variable in an enclosing block or a range variable previously defined in the query expression.

1
  • 2
    Why are you comverting StationId to string and assigning it to an integer variable? Commented Aug 15, 2012 at 13:40

1 Answer 1

3

I think the issue is that your variable, StationId, is being declared somewhere already within the same scope. Try changing to:

Dim SeqNumQuery = From a In db.RequestedServices
                          Where a.RequestedServiceId = id
                          Select a.StationId

StationId = SeqNumQuery.ToString

But look into what the other variable is being used for. If you need it, use something other than StationId for your variable name, for example RequestedServicesStationId.

More information regarding this error:

Range variable hides a variable in an enclosing block or a range variable previously defined in the query expression.


On a side note, I don't understand why you are using .ToString extension method. This won't cause your script to throw an exception, however I would recommend changing this to CInt():

StationId = CInt(SeqNumQuery)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.