Monday, March 26, 2012

Object reference not being returned

I have two functions, one calls the other. I haven't been able to figure out why I am getting nothing returned. The exception is thrown on the objCommand.ExecuteNonQuery() Thanks for looking

Dave

First Function

Sub AddNewUser()

Dim objUserFunctions As UserFunctions = New UserFunctions()
Dim objUserInfo As UserInfo = New UserInfo()
Dim objProviderFunctions As ProviderFunctions = New ProviderFunctions()
Dim objProviderInfo As ProviderInfo = New ProviderInfo()

objProviderInfo = objProviderFunctions.GetProviderID(txtProviderName.Text)
objUserInfo = objUserFunctions.PasswordGen(txtProviderName.Text, txtProviderContactName.Text)

objUserFunctions.AddUser(txtProviderEmail.Text, objUserInfo.UserPassword, txtProviderContactName.Text, objProviderInfo.ProviderID, 0)

End Sub

Second Function

Public Function GetProviderID(ByVal ProviderName As String) As ProviderInfo
Dim objConnection As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim objCommand As SqlCommand = New SqlCommand("GetProviderID", objConnection)
Dim objProviderInfo As ProviderInfo = New ProviderInfo()

Dim parameterProviderName As SqlParameter = New SqlParameter("@dotnet.itags.org.ProviderName", SqlDbType.NVarChar, 100)
Dim parameterProviderID As SqlParameter = New SqlParameter("@dotnet.itags.org.ProviderID", SqlDbType.Int, 4)

Try
'MARK COMMAND AS STORED PROCEDURE
objCommand.CommandType = CommandType.StoredProcedure

'INPUT PARAMETERS
parameterProviderName.Value = ProviderName
objCommand.Parameters.Add(parameterProviderName)

'OUTPUT PARAMETERS
parameterProviderID.Direction = ParameterDirection.Output
objCommand.Parameters.Add(parameterProviderID)

'OPEN THE CONNECTION AND EXECUTE THE COMMAND
objConnection.Open()
objCommand.ExecuteNonQuery()
objConnection.Close()

objProviderInfo.ProviderID = parameterProviderID.Value

GetProviderID = objProviderInfo

Catch e As Exception
Console.WriteLine()
Console.WriteLine()
Console.WriteLine("The following exception occured:")
Console.WriteLine("Exception : " + e.ToString())
Console.WriteLine("Message : " + e.Message)
Console.WriteLine("StackTrace : " + e.StackTrace)

Finally
objConnection = Nothing
objCommand = Nothing
objProviderInfo = Nothing
parameterProviderName = Nothing
parameterProviderID = Nothing

End Try

End FunctionCan you please post the complete output of those lines:

Console.WriteLine("The following exception occured:")
Console.WriteLine("Exception : " + e.ToString())
Console.WriteLine("Message : " + e.Message)
Console.WriteLine("StackTrace : " + e.StackTrace)

For now, I can't see any errors in your code.
I already fixed it, it was a damn error in my sproc. Thanks anyway!

0 comments:

Post a Comment