getting too many argument error, whr i am doing mistake-- urgent [Resolved]

Posted by Rickeybglr under ASP.NET on 9/12/2011 | Points: 10 | Views : 1361 | Status : [Member] | Replies : 2
i am verifying user, if username exist in DB page will redirect to home page else get error message. i am providing my code along wid SP. let me knw wat i am doing wrong.
.cs code:
public void loginVerified(string strName,string strPassword)
{
con.Open();
try {
SqlCommand cmdInsert = new SqlCommand("sp_login", con);
cmdInsert.CommandType = CommandType.StoredProcedure;
cmdInsert.Parameters.AddWithValue("@username", strName);
cmdInsert.Parameters.AddWithValue("@password", strPassword);

SqlParameter sqlParam = new SqlParameter("@validUser", SqlDbType.NVarChar);
sqlParam.Direction = ParameterDirection.Output;
cmdInsert.Parameters.Add(sqlParam);
sqlParam.Size = 6;
cmdInsert.ExecuteNonQuery();
string uName = cmdInsert.Parameters["@validUser"].Value.ToString();
if (uName == strName)
HttpContext.Current.Response.Redirect("Home.aspx");
else
HttpContext.Current.Response.Write("invalid user");
}
catch (Exception ee)
HttpContext.Current.Response.Write("error : " + ee.Message.ToString());
finally
con.Close();
}


SP:
ALTER PROCEDURE [dbo].[sp_login]( @username nvarchar (50),@password nvarchar (50))

AS
BEGIN
DECLARE
@validUser nvarchar(50)

SET @validUser= (SELECT username
from tb_registration
where username=@username AND password=@password);
select @validUser




Responses

Posted by: Kasibabu on: 9/12/2011 [Member] Starter | Points: 50

Up
0
Down

Resolved
Hi Rickeybglr


you prepared 3 parameters(@username,@password,@validuser) in application but
you created 2 parameters stored procedure so application says
you prepared too many arguments.

NOTE: we need explictly specify the output parameter in procedure

change the procedure like below

ALTER PROCEDURE [dbo].[sp_login]( @username nvarchar (50),@password nvarchar (50),@validUser nvarchar(50) output)
AS
BEGIN
SET @validUser= (SELECT username
from tb_registration
where username=@username AND password=@password);
select @validUser
end


if it helps make it as answer

Regards,
Kasi babu

Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rickeybglr on: 9/12/2011 [Member] Starter | Points: 25

Up
0
Down
hey thnx kashibabu...but i have doubt wat is the differ. betwwen both :
ALTER PROCEDURE [dbo].[sp_login]( @username nvarchar (50),@password nvarchar (50),@validUser nvarchar(50) output)

AND


ALTER PROCEDURE [dbo].[sp_login]( @username nvarchar (50),@password nvarchar (50))

AS
BEGIN
DECLARE
@validUser nvarchar(50)


Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response