Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
rtutus
Aged Yak Warrior
522 Posts |
Posted - 2006-05-10 : 20:55:35
|
My stored procedure works perfectly when I run Query Analyser, but when I run my VB program I get the eror: An SqlParameter with ParameterName 'total' is not contained by this SqlParameterCollection.Here is my stored Proc and my VB program is right belowI- Stored Proc:CREATE PROCEDURE dbo.totalsub @account bigint,@total bigint outputASselect total=sum(SubPhnNmbr) from tblsub where SubAccNmbr=@accountreturnGOII- And my pogram in VB is: Dim totsub As Int64 Dim cm As New SqlCommand Dim cn As New MyConnection cn.open 'my connection is defined by me don't worry about it cm.CommandType = CommandType.StoredProcedure cm.CommandText = "totalsub" cm.Connection = cn Dim pm As SqlParameter pm = cm.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Account", System.Data.SqlDbType.BigInt)) pm.Value = 100000165 pm = cm.Parameters.Add(New System.Data.SqlClient.SqlParameter("total", System.Data.SqlDbType.BigInt, 4)) pm.Direction = ParameterDirection.Output totsub = cm.Parameters("total").Value cm.ExecuteScalar() totsub = cm.Parameters("total").ValueI also tried using @total instead of total and I tried ParameterDirection.ReturmValue instead of ParameterDirection.OutputNo Luck, someone pls can help |
|
dfiala
Posting Yak Master
116 Posts |
Posted - 2006-05-10 : 21:10:55
|
You're close... pm = cm.Parameters.Add(New System.Data.SqlClient.SqlParameter("@total", System.Data.SqlDbType.BigInt, 4)) pm.Direction = ParameterDirection.InputOutputis what you need.And change this @total bigint outputto@total bigint output = null |
 |
|
rtutus
Aged Yak Warrior
522 Posts |
Posted - 2006-05-10 : 22:15:41
|
Cool I added the @ before total. now it seemes to be working, but I get a conversion error:Exception Details: System.Data.SqlClient.SqlException: Arithmetic overflow error converting expression to data type intThanks alot for your help |
 |
|
dfiala
Posting Yak Master
116 Posts |
Posted - 2006-05-10 : 22:25:42
|
try thisselect @total=sum(SubPhnNmbr) from tblsub where SubAccNmbr=@account |
 |
|
rtutus
Aged Yak Warrior
522 Posts |
Posted - 2006-05-11 : 09:15:31
|
that s what i m doing, may be there is a mistake in eiher the declaration of the parameter @total type or my SubPhnNmbr column type (bigint) in the database.Thanks. |
 |
|
|
|
|