sql server - Stored procedure expects parameter which was not supplied - what's the cause? -


this error code

when execute exception occurs.

stored procedure or function expects parameter not supplied.

this code:

string cs = configurationmanager.connectionstrings["conn"].tostring();   sqlconnection conn = new sqlconnection(cs);  conn.open();   sqlcommand cmd = new sqlcommand("sp_login",conn);   cmd.parameters.addwithvalue("@username",login.username.tostring());  cmd.parameters.addwithvalue("@pass", login.password);   = convert.toint32(cmd.executescalar());   conn.close(); 

you're not specifying you're calling stored procedure - change code to:

string cs = configurationmanager.connectionstrings["conn"].tostring();   // put connection , command "using" blocks using (sqlconnection conn = new sqlconnection(cs))  using (sqlcommand cmd = new sqlcommand("dbo.sp_login", conn)) {     // tell command it's callign *stored procedure*!      cmd.commandtype = commandtype.storedprocedure;      // don't use .addwithvalue - use .add() , *specify* datatype!     cmd.parameters.add("@username", sqldbtype.varchar, 50).value = login.username.tostring());      cmd.parameters.add("@pass", sqldbtype.varchar, 50).value = login.password);       // open connection, execute query, close connection     conn.open();      = convert.toint32(cmd.executescalar());      conn.close(); } 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -