Wednesday 15 September 2010

c# - Return value in a method that call store proc -



c# - Return value in a method that call store proc -

i using microsoft.practices.enterpriselibrary accessing sql info base of operations in c# code. have method phone call store proc , send parameter store proc, in homecoming store proc homecoming row(username , password). not sure how homecoming value in method. code:

public model.login getusernameandpasswordbypartnerid(int partnerid) { model.login login; string myconnection = system.configuration.configurationmanager.connectionstrings[connectionname].tostring(); sqldatabase db = new sqldatabase(myconnection); using (dbcommand command = db.getstoredproccommand("as_authenticatebypartner")) { db.addinparameter(command, "partnerid", dbtype.string, partnerid); seek { login= db.executescalar(command); //error on line // rtn = message("success", "acquisition", "getlogin", "service", db.executescalar(command).tostring()); } grab (exception ex) { } db = null; homecoming login; } }

and model.login

public class login { public string username; public string password; }

i not sure how should have line:

login= db.executescalar(command);

now getting error cannot explicitly convert object model.login.

this error because of object homecoming of next statement.

login= db.executescalar(command);

you have this

login= (model.login)db.executescalar(command);

but not solve problem executescalar not homecoming .net type login. useful if homecoming int ,string etc sql server. help on need know homecoming stored procedure.

if assume returning

select username,password tbluser

then can not utilize executescalar utilize homecoming single value.

you have this.

model.login model = null; var result = db.executereader(); if (!reader.hasrows) model = null; else { reader.read(); model = new model.login(){ username = reader.getstring(0) , password= reader.getstring(1) }; }

c# enterprise-library

No comments:

Post a Comment