I have a component that returns a value from a Sql Count statement... unfortunately I get the following error: System.NullReferenceException: Object reference not set to an instance of an object.
My component code:
Function GetCount(varAccountNumber as String) as String
conSqlConnect = New SqlConnection( "..." )
conSqlConnect.Open()
cmdSelect = New SqlCommand( "SELECT Count([account number]) AS Total From some_table Where [account number]=@dotnet.itags.org.accountnumber", conSqlConnect )
cmdSelect.Parameters.Add( "@dotnet.itags.org.accountnumber", varAccountNumber )
Return (cmdselect.executescalar())
conSqlConnect.Close()
End Function
on my code-behind page. I have
If myComponent.GetCount(user.identity.name) = 0 Then
'do something
End If
any suggestions?Which line caused this error?
>>Which line caused this error?
If myComponent.GetCount(user.identity.name) = 0 Then
What is "myComponent" ? It seems that it is not set correctly. Make sure that you initialize it the way it needs to be.
Yes I did initialize mycomponent like so:
Dim MyComponent as MyComponentClass
myComponent = New MyComponentClass()
any suggestions?
Either the component or the user.identity.name is causing the error. Try to debug the GetCount function of your component and also check if user.identity.name contains any value. At last I would say that debugging is the only way. Try quickwatch in Visual Studio.
Hope that it helped at least a little bit.
0 comments:
Post a Comment