heyday2004
asked on
A question about "error converting data type varchar to int".
When I run below code (in the try...catch... block), I kept getting error message:"error converting data type varchar to int". I checked the database table and the variables in the program, there is no where defined as int type, all are varchar type. So why does this message show up? It's related with the output parameter in stored proc? Thanks a lot for any suggestions!
The simplified code block:
objCmd = New OleDb.OleDbCommand
objCmd.CommandText = "dbo.usp_CheckStatus"
objCmd.Parameters.Add("@st atus_messa ge", SqlDbType.VarChar)
objCmd.Parameters("@status _message") .Direction = ParameterDirection.Output
objCmd.CommandType = CommandType.StoredProcedur e
objCmd.Connection = objConn
Try
objCmd.ExecuteNonQuery()
Catch ex As OleDbException '
MessageBox.Show(ex.Message )
End Try
The simplified stored proc:
create proc usp_CheckStatus
@status_message varchar(20) out
as
set @status_message = 'abcde'
return
The simplified code block:
objCmd = New OleDb.OleDbCommand
objCmd.CommandText = "dbo.usp_CheckStatus"
objCmd.Parameters.Add("@st
objCmd.Parameters("@status
objCmd.CommandType = CommandType.StoredProcedur
objCmd.Connection = objConn
Try
objCmd.ExecuteNonQuery()
Catch ex As OleDbException '
MessageBox.Show(ex.Message
End Try
The simplified stored proc:
create proc usp_CheckStatus
@status_message varchar(20) out
as
set @status_message = 'abcde'
return
Hi heyday2004,
If you run the stored proc command in query analyser do you get the sam error? If so the prob is with proc not code in which case we can move on from there, try it out
Apresto
If you run the stored proc command in query analyser do you get the sam error? If so the prob is with proc not code in which case we can move on from there, try it out
Apresto
DECLARE @MyVar varchar(20)
exec usp_CheckStatus @MyVar
Print @MyVar
run that in query analyser
exec usp_CheckStatus @MyVar
Print @MyVar
run that in query analyser
ASKER
Thanks for the reply. That's the whole stored proc, I've simplified to that extent but still couldn't find out the problem. It's still reporting :"error converting data type varchar to int". I guess it's related with the output parameter? BTW, it runs good in query analyzer. What does your above query mean? I ran it and returns nothing although succeeded, i think that's the right result. Anyway, any further suggestion is really appreciated. Thanks.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yeah, anywhere is wrong in the program in using the output parameter? Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a lot. Great help for me.
Can we see the rest of the sp? Does it still happen even with your simplified sp?
Tim Cottee