SQL Server - procedure or function transfertcash has too many arguments specified

Asked By Daniel
29-Aug-11 10:30 AM

Hi!can anyone help pliz...
I am using c#.net 2010 and sql sever 2008.I am getting the following error:
<<Procedure or function transfertcash has too many arguments specified>>.

 

protected void BtnSend_Click(object sender, EventArgs e)
      {
        SqlConnection sqlconnection = new SqlConnection("Data source=NDEKEZIDANIEL\\SQLEXPRESS;Initial catalog=ECASH;integrated security=true");

 

          SqlCommand sqlcommand = new SqlCommand("transfertcash", sqlconnection);
          sqlcommand.Parameters.Add("@numb", SqlDbType.BigInt).Value = Int64.Parse(TextBoxBenTel.Text.Trim());
          sqlcommand.Parameters.Add("@montant", SqlDbType.Int).Value = Int32.Parse(TextBoxMontant.Text.Trim());
          sqlcommand.Parameters.Add("@numtel", SqlDbType.BigInt).Value = Session["num_tel"];
          sqlcommand.Parameters.Add("@code", SqlDbType.NVarChar,50).Value = TextBoxPassword.Text.Trim();
          sqlcommand.Parameters.Add("@msg_to_send", SqlDbType.NVarChar, 4000).Value = "";
          sqlcommand.Parameters["@msg_to_send"].Direction = ParameterDirection.Output;
          sqlcommand.Parameters.Add("@returnValue",SqlDbType.Int).Value=ParameterDirection.ReturnValue;

          else
          {
        
          sqlconnection.Open();
          sqlcommand.CommandType = CommandType.StoredProcedure;
          sqlcommand.ExecuteNonQuery();
         
          int exists = (int)sqlcommand.Parameters["@returnValue"].Value;
          if (exists == 1)
          {
            Lblsms.Text = "<font color='green'>Ecash transfered successfully!</font>";
          }
          else
          {
            Lblsms.Text = "<font color='red'>Transfer failed,please contact the service center!";
          }
          sqlconnection.Close();
        }
      }

      #endregion
    }

and i have the following stored precedure:

ALTER PROC [dbo].[transfertcash]
(
@numb BIGINT,
@montant INT,
@numtel BIGINT,
@code NVARCHAR(50),
@msg_to_send as NVARCHAR(4000) OUTPUT
)
AS
BEGIN

 DECLARE @AccountStatus  varchar(50)
 DECLARE @AvailableBalance INT
 DECLARE @TransactionID BIGINT
 DECLARE @nom VARCHAR(50)
 DECLARE @prenom VARCHAR(50)

 IF NOT(@montant >= 1000 AND @montant <= 100000)
 BEGIN
  SET @msg_to_send= 'Invalid Amount! The amount must be in range 1000-100000'
  RETURN  0
 END
 
 --Ensure the number is valid and account is open
 IF EXISTS(Select numtel from MyLogin where numtel = @numtel AND idsession = @code )
 BEGIN
  --Check if his account is opened
  SET @AccountStatus = (select etat from McellAcc where  numtel = @numtel)
  IF(@AccountStatus = 'opened')
  BEGIN
   --Account is active make the transaction
   --Check if he has sufficient amount
   SET @AvailableBalance = (SELECT solde FROM McellAcc WHERE numtel = @numtel)
   IF(@AvailableBalance >= @montant)
   BEGIN
  --Transfer   the money
  BEGIN TRANSACTION
  --Debit the account   
  BEGIN TRY
  UPDATE McellAcc SET solde = solde - @montant WHERE numtel=@numtel
  INSERT INTO TransactionM(  --retrait cpte tigo
    numtel,
    debitmonta,
    creditmonta,
    DateTrans,
    taux,
    etat
    )
    values(
    @numtel,
    @montant,
    0,
    getdate(),
       (@montant * 5/100),
    'Pending...'
    )
     --RETURN 1
  SET @TransactionID = @@IDENTITY
  SET @nom=(SELECT nom FROM MyLogin WHERE numtel=@numtel)
  SET @prenom=(SELECT prenom FROM MyLogin WHERE numtel=@numtel)  
  SET @msg_to_send = 'You received '+''+'FRW'+cast(@montant AS VARCHAR(15))+' from '+@nom+' '+@prenom+'.The transaction ID: ' + CAST(@TransactionID AS VARCHAR(20))    
  INSERT INTO ozekimessageout(receiver,msg,[status]) VALUES (@numb,@msg_to_send,'send')      
  COMMIT TRANSACTION
  RETURN 1
  END TRY
  BEGIN CATCH
  ROLLBACK TRANSACTION
  SET @msg_to_send = 'Transfer failed! Please try again.'
  RETURN 0
  RETURN
  END CATCH
   
   END
   ELSE
   BEGIN
  -- Insufficient amount
  SET @msg_to_send= 'Insufficient Amount!'
  RETURN 0
   END  
   
   
  END
  ELSE
  BEGIN
   --Account is deactive, inform the user
   SET @msg_to_send= 'Account Deactive! You account is deactive, please activate your account'
   RETURN 0
  END
 END
 ELSE
 BEGIN
  -- Tell use his number is incorret
  SET @msg_to_send= 'Invalid Number!'
  RETURN 0
 END 
 END
 

  Peter Bromberg replied to Daniel
29-Aug-11 12:54 PM
Try removing the declaration of the returnval as an input paramter. The stored procedure does not define one.
Returnval is what you get as an integer result of the 

    sqlcommand.ExecuteNonQuery();

e.g, 
int retval =   sqlcommand.ExecuteNonQuery();

Create New Account
help
Best way to coordinate native date format between client and server? SQL Server Hello, I'm running into an issue in a VB application that uses SQL Server as a back end. I have a stored procedure that uses a From and To best practice" when it comes to syncronizing the regional settings between the Client and the SErver? Thanks! Rick SQL Server Programming Discussions SQL Server 2000 (1) SQL Server 2005 (1) SQL Server (1) SqlDbType.DateTime
space planning for SQL Server SQL Server Hi I am looking for a script that will enumerate all the DBs on a sql server, show me the used MB and the max MB allocated per db. My intent would isn’t returning anything on it. Can someone aim me in the right direction? thanks SQL Server Discussions SQL Server (1) Exec (1) Disk (1) SqlDataAdapter (1) Database (1) AdventureWorks (1) SqlParameter
Why_can’t_recursive_queries_contain. . .? SQL Server hi I hope I didn = 92t put too many questions 1) Why can = 92t recursive queries also be unioned together with UNION operator ( instead they must use UNION ALL )? thanx SQL Server Programming Discussions SQL Server 2008 (1) SQL Server 2005 (1) SQL Server 2000 (1) SQL Server (1) Oracle (1) Ruby (1) MichaelcoAToptonlineDOTnet (1
Import Data from Excel file to SQL server how to import data from excel file into the SQL server Use DTS or SSIS You can use the SQL Server Data Transformation Services (DTS) Import Wizard or the SQL Server Import and Export Wizard to import Excel data into SQL Server tables. Check this link
store image in sql server 2008 can any one tell me the code for storing images in sql server 2008 with c# thanks in advance To Save images to SQL Server 2005 DB http: / / www.aspsnippets.com / post / 2009 / 02 / 19 / Save-and-Retrieve-Files-from SQL-Server-Database-using-ASPNet.aspx To retreive and display http: / / www.aspsnippets.com / post / 2009 / 02