Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error running stored procedure - object must implement IConvertible

Status
Not open for further replies.

BiggerD

Programmer
Jun 19, 2002
43
GB
here is the code when it gets to .executenonquerty the above error occurs any ideas? the sp is ok as it runs in query analyser.
and the parameters all appear to be created successfully.

Public Shared Function ExecuteSPReturnValue(ByVal cnConnectionString As String, ByVal SPtoRun As String, ByVal ReturnParameter As SqlParameter, _
ByVal ParamArray Parameters() As SqlParameter) As Integer


'to execute a stored procedure and not return anything.
Dim objConnection As New SqlConnection(cnConnectionString)
Dim objCmd As SqlCommand

objConnection.Open()
objCmd = objConnection.CreateCommand()

Try
With objCmd
' .Connection = objConnection
.CommandType = CommandType.StoredProcedure
.CommandText = SPtoRun
.Parameters.Add(ReturnParameter)

AddParameters(objCmd, Parameters)
.ExecuteNonQuery()
ExecuteSPReturnValue = ReturnParameter.Value
End With

Catch ex As Exception
MsgBox(Err.Description)
End Try

objCmd = Nothing
objConnection.Close()
objConnection = Nothing

'If Parameters.Length > 0 Then
' For intparameter As Integer = 0 To Parameters.Length - 1
' If Not Parameters(intparameter) Is Nothing Then
' .Parameters.Add(Parameters(intparameter))
' End If
' Next
'End If()
End Function
 
I suspect that you sp is select statement?



Christiaan Baes
Belgium

"Time for a new sig." - Me
 
the sp is an insert see below

CREATE PROCEDURE sp_Title_Insert

@ID NUMERIC OUTPUT,
@Description VARCHAR(100),
@Active BIT,
@Default BIT


AS

INSERT INTO TBL_TITLES

([Description],Active,Isdefault)

VALUES

(@Description,@Active,@Default)


set @ID= @@Identity

SELECT @ID
GO
 
try executescalar()


Christiaan Baes
Belgium

"Time for a new sig." - Me
 
i have at last spotted the issue
the calling code :

objLookup.ID = ExecuteSPReturnValue(fnConnectionString, CreateParameter("ID", SqlDbType.Int, 4, ParameterDirection.Output), _
Sp_To_Run_Insert, _
CreateParameter("Description", SqlDbType.VarChar, objLookup.Description), _
CreateParameter("Active", SqlDbType.Bit, IIf(objLookup.Active = True, 1, 0), _
CreateParameter("Default", SqlDbType.Bit, IIf(objLookup.IsDefault = True, 1, 0))))


looked as above.

Ihave a bracket missing here :
CreateParameter("Active", SqlDbType.Bit, IIf(objLookup.Active = True, 1, 0)***)***, and thus an extra one on the end of the line fixed this and fixed the prob.

Thanks Chrissie1 for taking the trouble to help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top