Windows Forms: Procedure or function has too many arguments specified.

Last Reply on Sep 17, 2013 03:48 AM By Mudassar

Posted on Sep 17, 2013 03:46 AM

im working with this code;

 

 i have stored procedure :

 

ALTER PROCEDURE [dbo].[Insert_target]
	
	@year_covered int,
	@region int,
	@province int,
	@project int,
	@municipality varchar(50),
	@subproject varchar(50),
	@allocation int,
	@target_new int,
	@target_restore int,
	@target_rehab int,
	@target_fb int,
	@target_job int,
	@idd int output


AS

	BEGIN

	 SET NOCOUNT ON;
	  
	 Insert into tbltarget (year_covered, region, province, municipality, project, subproject, allocation, 	  target_new, target_restore, target_rehab, target_fb, target_job) 
values (@year_covered,@region,@province,@municipality, @project,@subproject,@allocation,@target_new,@target_restore,@target_rehab,@target_fb,@target_job)
	set @idd = scope_identity()
	return @idd

	END
 
 

My Code : 

 

 

For Each lv In ListView1.Items

            dbCommand.CommandType = CommandType.StoredProcedure
            dbCommand.CommandText = "Insert_target"
       
            dbCommand.Parameters.AddWithValue("@year_covered",CInt(ListView1.Items(i).Text.ToString))
            dbCommand.Parameters.AddWithValue("@region", CInt(REGION))
            dbCommand.Parameters.AddWithValue("@province", CInt(PROVINCE))
            dbCommand.Parameters.AddWithValue("@municipality", ListView1.Items(i).SubItems(6).ToString)
            dbCommand.Parameters.AddWithValue("@project", CInt(PROJECT))
            dbCommand.Parameters.AddWithValue("@subproject", ListView1.Items(i).SubItems(7).ToString)
            dbCommand.Parameters.AddWithValue("@allocation", CInt(ListView1.Items(i).SubItems(8).Text.ToString))
            dbCommand.Parameters.AddWithValue("@target_new", CInt(ListView1.Items(i).SubItems(9).Text.ToString))
            dbCommand.Parameters.AddWithValue("@target_restore", CInt(ListView1.Items(i).SubItems(10).Text.ToString))
            dbCommand.Parameters.AddWithValue("@target_rehab", CInt(ListView1.Items(i).SubItems(11).Text.ToString))
            dbCommand.Parameters.AddWithValue("@target_fb", CInt(ListView1.Items(i).SubItems(12).Text.ToString))
            dbCommand.Parameters.AddWithValue("@target_job", CInt(ListView1.Items(i).SubItems(13).Text.ToString))
            dbCommand.Parameters.Add("@idd", SqlDbType.Int).Direction = ParameterDirection.Output

            dbCommand.Connection = dbConnection

             Try

            dbCommand.ExecuteNonQuery()
            Dim ids As String = dbCommand.Parameters("@idd").Value.ToString
         
            Catch ex As Exception
          MessageBox.Show(ex, MessageBoxButtons.OK, MessageBoxIcon.Information)
           End Try

        Next

Im hoping someone could help me...  

Posted on Sep 17, 2013 03:48 AM

You are looping and inserting but using the same SqlCommand hence it is throwing this error. Hence add the following line before adding new Parameters

dbCommand.Parameters.Clear();

 

I agree, here is the link: https://www.e-iceblue.com/Introduce/spire-office-for-net-free.html