PeteEngineer
asked on
Object reference not set to an instance of an object.
I am getting the following error from the below procedure at the high lighted line :
"Object reference not set to an instance of an object."
error line : _CopyWorkflowItemID = command.ExecuteScalar().To String()
Function:
Please help me !
"Object reference not set to an instance of an object."
error line : _CopyWorkflowItemID = command.ExecuteScalar().To
Function:
Function GetWorkFlowItemId(ByVal StID As String) As String
Dim connection As SqlConnection = Nothing
Try
connection = New SqlConnection(strConnection)
Dim command As New SqlCommand(Me.GetSPX("spx_StCopyForm_SELECT"), connection)
command.CommandType = CommandType.StoredProcedure
Dim StIDParam As SqlParameter = New SqlParameter("@StID", SqlDbType.VarChar, 50)
StIDParam.Value = StID
command.Parameters.Add(StIDParam)
Dim StSetParam As SqlParameter = New SqlParameter("@StSet", SqlDbType.Int)
StSetParam.Value = _StSet
command.Parameters.Add(StSetParam)
Dim workflowIDParam As SqlParameter = New SqlParameter("@WorkflowID", SqlDbType.VarChar, 50)
workflowIDParam.Value = _WorkflowID
command.Parameters.Add(workflowIDParam)
connection.Open()
_CopyWorkflowItemID = command.ExecuteScalar().ToString()
If Not String.IsNullOrEmpty(_CopyWorkflowItemID) Then
If _CopyWorkflowItemID <> _WorkflowItemID Then
Return _CopyWorkflowItemID
End If
End If
Finally
If Not connection Is Nothing Then connection.Close() : connection.Dispose()
End Try
Return _WorkflowItemID
End Function
Please help me !
Instead of
_CopyWorkflowItemID = command.ExecuteScalar().To String()
does this work
Object obj = command.ExecuteScalar()
if not isnull(obj) then _CopyWorkflowItemID = obj.ToString()
_CopyWorkflowItemID = command.ExecuteScalar().To
does this work
Object obj = command.ExecuteScalar()
if not isnull(obj) then _CopyWorkflowItemID = obj.ToString()
Check that spx_StCopyForm_SELECT always returns a value regardless of whether data is affected or not
ASKER
I found no data in table ... and nor inserting any thing into this table anywhere in the application.
So can we do an error handling here .. ?
How to do that ...
can we do by checking null of that object using a if statement
if so , what we can write in the else statement to handle this ?
Please write the code by editing my previous function posted in question.
So can we do an error handling here .. ?
How to do that ...
can we do by checking null of that object using a if statement
if so , what we can write in the else statement to handle this ?
Please write the code by editing my previous function posted in question.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
its just a select command :
ALTER PROCEDURE [dbo].[spx_StDetailCopyForm_SELECT](
@StyleID uniqueidentifier,
@StyleSet int,
@WorkflowID uniqueidentifier)
AS
BEGIN
SELECT WorkFlowItemId
FROM pStDetailForm
WHERE StyleID = @StyleID AND
StyleSet = @StyleSet AND
WorkflowID = @WorkflowID
END
>>can we do by checking null of that object using a if statement
See my first comment.
I'm not a VB specialist but basically split that line into two lines of code - so you can check if the command.ExecuteScalar is actually returning an object or null.
See my first comment.
I'm not a VB specialist but basically split that line into two lines of code - so you can check if the command.ExecuteScalar is actually returning an object or null.
ASKER
yes it is null ,
but i want to know what sepecally i need to handle ..what to put in else statement if it is not null
but i want to know what sepecally i need to handle ..what to put in else statement if it is not null
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok
H!!
Where is _StSet and _WorkflowID declared?
Thanks!
Where is _StSet and _WorkflowID declared?
Thanks!
ASKER