0

I get a NullReferenceException error while saving a record with following statement:

Dim sel As String = "select COUNT(*) from Master_URLEntry where Projectname='" &0 G_Current_Project & "'  and ListCode like '%" & sCode & "%' "]
If blnAdd = False Then
  sel += "and Recordid not in ('" & _dtMasterRow.Item("RecordID") & "')"
End If
Cœur
  • 37,241
  • 25
  • 195
  • 267
ArunRC
  • 9
  • 3
  • 3
    Possible duplicate of [What is a NullReferenceException and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Jay Mar 02 '16 at 08:14
  • and beware of sql injection – Fredou Mar 02 '16 at 13:43

1 Answers1

0
NullReferenceException 

means in simple words that you are got getting one of the values that you think you should. Put a breakpoint right before this and step through with F11. When a line will be yellow hover with mouse over each variable and check if it has value.

Find which one is causing an exception and work back words to see whats wrong because there is nothing wrong wit above statement.

My educated guess is that this _dtMasterRow.Item("RecordID") has no value for some reason.

Claudius
  • 1,883
  • 2
  • 21
  • 34