Click here to Skip to main content
11,712,727 members (80,114 online)
Rate this: bad
good
Please Sign up or sign in to 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

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 3-Apr-13 23:36pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I guess your parameters are not being cleared. Add this line just before adding the parameters:
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.
  Permalink  

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

  Print Answers RSS
0 CHill60 335
1 Sergey Alexandrovich Kryukov 300
2 OriginalGriff 230
3 Andy Lanng 160
4 Maciej Los 130
0 CHill60 335
1 Sergey Alexandrovich Kryukov 300
2 OriginalGriff 230
3 Andy Lanng 160
4 Maciej Los 130


Advertise | Privacy | Mobile
Web04 | 2.8.150819.1 | Last Updated 4 Apr 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100