Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello friends,


I am getting "Procedure or function SP_UpGridDateDetails has too many arguments specified." error when i am updating the grid.

My code like this...
In Data Access Layer..

foreach (CO_TR_Registration objCO_TR_Registration in ObjGridCO_TR_Registration)
               {


                   objSqlCommand.Parameters.Add("@regId", SqlDbType.VarChar).Value = (objCO_TR_Registration.RegistrationID);
                   objSqlCommand.Parameters.Add("@VlFNo", SqlDbType.VarChar).Value = (objCO_TR_Registration.VLFNO).TrimEnd() ;
                   objSqlCommand.Parameters.Add("@Stud_name", SqlDbType.VarChar).Value = objCO_TR_Registration.Name;
                   objSqlCommand.Parameters.Add("@FHG", SqlDbType.VarChar).Value = objCO_TR_Registration.FHG;
                   objSqlCommand.Parameters.Add("@FHG_Name", SqlDbType.VarChar).Value = objCO_TR_Registration.FatherName;
                   objSqlCommand.Parameters.Add("@MaritalStatus", DbType.String).Value = objCO_TR_Registration.MaritalStatus;
                   objSqlCommand.ExecuteNonQuery();

               }

and stored procedure..

VB
UPDATE [KMDCModified].[dbo].[Register]
   SET


       [VLFNo]=@VlFNo
      ,[stud_name] = @Stud_name
      ,[FHG] = @FHG
      ,[FHG_Name] = @FHG_Name

      ,[maritalstatus] = @maritalstatus

 WHERE regid=@regId



in secong loop its getting error
Posted
Updated 22-Jun-11 21:18pm
v2
Comments
walterhevedeich 23-Jun-11 3:19am    
Can you post the whole script of the stored procedure?
jagadeesh123qqq 23-Jun-11 3:20am    
ALTER PROC [dbo].[SP_UpGridDateDetails]
(
@regId int,

@VlFNo Varchar(15),
@Stud_name varchar(100),
@FHG char,
@FHG_Name Varchar(100),

@MaritalStatus char


)
AS
BEGIN


UPDATE [KMDCModified].[dbo].[Register]
SET


[VLFNo]=@VlFNo
,[stud_name] = @Stud_name
,[FHG] = @FHG
,[FHG_Name] = @FHG_Name

,[maritalstatus] = @maritalstatus

WHERE regid=@regId

END

jagadeesh123qqq 23-Jun-11 3:36am    
Hi,
Have u got?
jagadeesh123qqq 23-Jun-11 3:19am    
ALTER PROC [dbo].[SP_UpGridDateDetails]
(
@regId int,

@VlFNo Varchar(15),
@Stud_name varchar(100),
@FHG char,
@FHG_Name Varchar(100),

@MaritalStatus char


)
AS
BEGIN


UPDATE [KMDCModified].[dbo].[Register]
SET


[VLFNo]=@VlFNo
,[stud_name] = @Stud_name
,[FHG] = @FHG
,[FHG_Name] = @FHG_Name

,[maritalstatus] = @maritalstatus

WHERE regid=@regId

END

1 solution

As it is the second loop round that gives the error it is fairly obvious: Don't use
objSqlCommand.Parameters.Add("@...", SqlDbType.VarChar).Value = ...);
in your loop unless you also create a new objSqlCommand in the loop as well.

Otherwise, you already have a parameter of that name, with a value, which can only get confusing.

BTW: Parameters.Add is depreciated in favour of Parameters.AddWithValue, which does not require the datatype.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900