ALTER PROCEDURE [dbo].[Insert_Addres](@Country_id int,
@City_name nvarchar(255),
@Post_code nvarchar(50),
@Address nvarchar(50),
@AddressID int OUTPUT
)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
INSERT INTO dbo.Address
(
[Country_ID],
[City_Name],
[Post_Code],
[Address]
)
VALUES
(
@Country_id ,
@City_name ,
@Post_code ,
@Address
) ;
SET @AddressID = Scope_Identity()
return @AddressID
END
zeeshanfazal
Member
9 Points
40 Posts
Procedure or function Insert_Addres has too many arguments specified.
May 05, 2012 08:07 AM|LINK
ALTER PROCEDURE [dbo].[Insert_Addres](@Country_id int,
@City_name nvarchar(255),
@Post_code nvarchar(50),
@Address nvarchar(50),
@AddressID int OUTPUT
)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
INSERT INTO dbo.Address
(
[Country_ID],
[City_Name],
[Post_Code],
[Address]
)
VALUES
(
@Country_id ,
@City_name ,
@Post_code ,
@Address
) ;
SET @AddressID = Scope_Identity()
return @AddressID
END
******************************************************************
C sharp Code
cmd.CommandText = "[dbo].[Insert_Addres]";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@Country_id", Country_drpdwn.SelectedValue);
cmd.Parameters.Add("@City_name", City_txt.Text);
cmd.Parameters.Add("@Post_code", Postcode_txt.Text);
cmd.Parameters.Add("@Address", Address_txt.Text);
cmd.Parameters.Add("@AddressID" ,SqlDbType.Int).Direction = ParameterDirection.Output;
Int16 addressid = Convert.ToInt16(cmd.Parameters["@AddressID"].Value);
urenjoy
Star
11997 Points
1797 Posts
Re: Procedure or function Insert_Addres has too many arguments specified.
May 05, 2012 08:30 AM|LINK
try
1. Use AddWithValue insteat of Add:
cmd.Parameters.AddWithValue ("@Country_id", Country_drpdwn.SelectedValue);
2.
cmd.Parameters.Add("@AddressID" ,SqlDbType.Int);
cmd.Parameters["@AddressID"].Direction = ParameterDirection.Output;
3.
Remove Return statement from stored proc
zeeshanfazal
Member
9 Points
40 Posts
Re: Procedure or function Insert_Addres has too many arguments specified.
May 05, 2012 09:24 AM|LINK
Hello urenjoy
Thanks 4 reply...i followed ur instructions but still gives me that error
any alternate please ...
kirupa.v
Contributor
2070 Points
531 Posts
Re: Procedure or function Insert_Addres has too many arguments specified.
May 05, 2012 09:29 AM|LINK
Hi,
There is no such parameter named @Country_id in your Stored Procedure.
But u r inserting it in ur SP ans in C# Code as well..
So only it is giving that error..
Just add that paramater @Country_id alone to your Stored Procedure and execute it..
It will work..
Reply me for any issues..
Chen Yu - MS...
All-Star
21569 Points
2493 Posts
Microsoft
Re: Procedure or function Insert_Addres has too many arguments specified.
May 09, 2012 08:37 AM|LINK
Hi,
I tested your stored procedure, it works fine. It seems that your C# code have some error. Please modify your code like below:
cmd.CommandText = "[dbo].[Insert_Addres]"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Country_id", Country_drpdwn.SelectedValue); cmd.Parameters.AddWithValue("@City_name", City_txt.Text); cmd.Parameters.AddWithValue("@Post_code", Postcode_txt.Text); cmd.Parameters.AddWithValue("@Address", Address_txt.Text); cmd.Parameters.Add("@AddressID" ,SqlDbType.Int) cmd.Parameters["@AddressID"].Direction = ParameterDirection.Output; Int16 addressid = Convert.ToInt16(cmd.Parameters["@AddressID"].Value);If your problem still here, please tell us as free.
Thanks.
Feedback to us
Develop and promote your apps in Windows Store
christiandev
Star
8597 Points
1841 Posts
Re: Procedure or function Insert_Addres has too many arguments specified.
May 09, 2012 10:05 AM|LINK
Country_id is already there, look immediately after the bracket...it isnt that clear, I agree.
try clearing the params, and put a breakpoint before calling the SP to see what the param collection looks like.
Regards, Christiandev (@chrisdev80), MCPD Web (2 & 4) & MCTS Windows (www.ScoreDonkey.com)