I have the following stored procedure:
ALTER PROCEDURE spLogin
@CAD_WEB_LOGIN_USERNAME varchar(60),
@CAD_WEB_LOGIN_PASSWORD varchar(60),
@Result int output
AS
BEGIN
SELECT
CAD_NUMBER
FROM
CMACADDR
WHERE
CAD_WEB_LOGIN_USERNAME = @CAD_WEB_LOGIN_USERNAME
AND CAD_WEB_LOGIN_PASSWORD = @CAD_WEB_LOGIN_PASSWORD
END
In C#, I want to execute this query and get the return value.
This is my code:
int flag = 0;
con.Open();
SqlCommand cmd3 = new SqlCommand("spLogin", con);
cmd3.Connection = con;
cmd3.CommandType = CommandType.StoredProcedure;
cmd3.Parameters.Add("@CAD_WEB_LOGIN_USERNAME", SqlDbType.VarChar).Value = txtUserName.Text;
cmd3.Parameters.Add("@CAD_WEB_LOGIN_PASSWORD", SqlDbType.VarChar).Value = txtPassword.Text;
SqlParameter parm = new SqlParameter("@Return", SqlDbType.Int);
parm.Direction = ParameterDirection.ReturnValue;
cmd3.Parameters.Add(parm);
flag = cmd3.ExecuteNonQuery();
con.Close();
int id = Convert.ToInt32(parm.Value);
I get an error:
Procedure or function 'spLogin' expects parameter '@Result', which was not supplied.
What's the logic error with this code?
Thanks
@Resultbut in your C# code, you're calling it@Return- those names must match !@Resultat SP and@Returnin cs page??