Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
This problem is creating when i Insert data SQL server with store procedure first time insert successfully but second time problem is create .
The problem is Procedure or function spUpdateDomain has too many arguments specified
my code is.

C# Code is

C#
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "spcontactInsert";
cmd.Parameters.AddWithValue("@ContactName ", UserName.Text);
cmd.Parameters.AddWithValue("@ContactAddress ", Address.Text);
cmd.Parameters.AddWithValue("@ContactEmail  ", email);
cmd.Parameters.AddWithValue("@PhoneNumber  ", phone);
cmd.Parameters.AddWithValue("@FirstMobNumber  ", FirstNumber.Text);
cmd.Parameters.AddWithValue("@SecondMobNumber  ", SecendNumber.Text);
cmd.Parameters.AddWithValue("@ThirdMobNumber  ", txt.Text);
con.Open();
cmd.Connection = con;
int i = cmd.ExecuteNonQuery();
con.Close();



SQL Store Procedure Code

ALTER PROCEDURE [dbo].[spcontactInsert]
@ContactName nvarchar(50),
@ContactAddress nvarchar(50),
@ContactEmail nvarchar(50),
@PhoneNumber nvarchar(50),
@FirstMobNumber bigint,
@SecondMobNumber bigint,
@ThirdMobNumber bigint
AS
BEGIN
if not exists(Select FirstMobNumber from ContactDB where FirstMobNumber=@FirstMobNumber)
begin
INSERT INTO ContactDB(ContactName, ContactAddress, ContactEmail,PhoneNumber,FirstMobNumber, SecondMobNumber, ThirdMobNumber)
VALUES (@ContactName,@ContactAddress,@ContactEmail,@PhoneNumber,@FirstMobNumber,@SecondMobNumber,@ThirdMobNumber)
end
END





Pleease solve my problem
Posted

1 solution

I guess your parameters are not being cleared. Add this line just before adding the parameters:
C#
cmd.Parameters.Clear();

If this doesn't solve your problem, use an SQL Profiler[^] to see what query exactly is passed to SQL. Try and execute that on SQL Query Analyzer.
 
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