0

Sorry to bother you on this, but I'm a little confused. I have this code in a sub called in Page_Load

Dim db As dbVulcanoEntities
Dim intervento As Interventi
Dim idint As Integer
idint = Request.QueryString("idint")
intervento = db.Interventi.Where(Function(i) i.IDInt = idint).Single

It fails on last line (in debug I see that idint has value) and if I query the db I get 1 record. Odd thing is that I used this exact same code in another page of the same project (more than once,actually) and it works with no problem... I can't understand why it's not working here... hints!? Thank you

EDIT: I tried to add a condition like this

 If db.Interventi.Any(Function(i) i.IDInt = idint) Then

but it doesn't even pass it, so I guess it doesn't like the "i.IDInt = idint" part for some reason.

  • It return a number, idint is an integer field of the interventi table, in this case it is passed from one page to another through querystring and in debug I can see its value. Please see the EDIT above, also I tried to use convert.toint32 on querystring but it fails anyway – Gabriele Cozzolino Sep 08 '17 at 08:04
  • 1
    You need to declare `db as new dbVulcanoEntities`. Also, consider implementing this in a [Using Statement](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/using-statement). – IronAces Sep 08 '17 at 08:05
  • _"with the same code already used and working"_ I strongly doubt that ;) – Tim Schmelter Sep 08 '17 at 08:07
  • @TimSchmelter a part from the missing "new" the rest was copy-pasted ;-) – Gabriele Cozzolino Sep 08 '17 at 09:01

1 Answers1

1

The code as posted will, indeed, produce a NullReferenceException as you are never assigning a value to the db local variable, so I am expecting it to be Nothing.

Kirill Shlenskiy
  • 9,367
  • 27
  • 39