How to use Execute Scaler?

Posts   
 
    
Posts: 97
Joined: 29-Apr-2009
# Posted on: 04-May-2009 09:19:07   

i have below query :

Select txtPassword From CMS_Admin where intUserID=1

so now i want to execute this query by using ExecuteScaler()

i am using self servicing here.

so please help me how to execute this query??? so it will return current password

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 04-May-2009 10:25:19   

Use a Dynamic List

Posts: 97
Joined: 29-Apr-2009
# Posted on: 04-May-2009 11:25:22   

Walaa wrote:

Use a Dynamic List

thanks for your valuable reply. i have already it but i cant get some idea. so can you please give me some code for that.

i am doing as below :

IRetrievalQuery query = RetrievalProcedures.GetProcCmsAdminAuthenticateCallAsQuery("admin", "admin");

int i = Convert.ToInt32(query.ExecuteScalar());

but it gives error that no connection available.

Thanks again in advanced

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 04-May-2009 14:31:38   

Are you calling a Stored Procedure or fetching a single column/value from a table?

Posts: 97
Joined: 29-Apr-2009
# Posted on: 05-May-2009 08:06:45   

Walaa wrote:

Are you calling a Stored Procedure or fetching a single column/value from a table?

hi thanks again

well i am fetching a single column value from a table not from store procedure.

Thanks

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 05-May-2009 08:53:36   

Then Why were you using the following?

IRetrievalQuery query = RetrievalProcedures.....

That's for calling a SP. Please check the link I posted before, and use a DynamicList.

Also you might use the GetScalar method as shown here

Posts: 97
Joined: 29-Apr-2009
# Posted on: 06-May-2009 05:29:07   

Walaa wrote:

Then Why were you using the following?

IRetrievalQuery query = RetrievalProcedures.....

That's for calling a SP. Please check the link I posted before, and use a DynamicList.

Also you might use the GetScalar method as shown here

Hi Walaa

Thanks for your such good reply. i have refer but i am new in this LLBLGen. so can you please help me to give some two three line code for that.

see i have one table called : admin

it has Three field : username & Password & UserID

i want to executescaler query that username & password is entered, if it is match with username & Password, it will return UserID.

so i can get value in Integer.

Thanks Walaa.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 06-May-2009 08:59:13   

i want to executescaler query that username & password is entered, if it is match with username & Password, it will return UserID.

I thought you needed to select the pswd given the id as you stated before:

i have below query :

Select txtPassword From CMS_Admin where intUserID=1

so now i want to execute this query by using ExecuteScaler()

Anyway, the code should look like the following For Adapter:

IPredicateExpression filter = new PredicateExpression();
filter.Add(CmsAdminFields.UserName == username);
filter.Add(CmsAdminFields.Password == pswd);

DataAccessAdapter adapter = new DataAccessAdapter();
int id = (int)adapter.GetScalar(CmsAdminFields.UserId, null, null, filter);

For SelfServicing:

IPredicateExpression filter = new PredicateExpression();
filter.Add(CmsAdminFields.UserName == username);
filter.Add(CmsAdminFields.Password == pswd);

CmsAdminCollection col = new CmsAdminCollection();
int id = (int)col.GetScalar(CmsAdminFields.UserId, null, null, filter);
Posts: 97
Joined: 29-Apr-2009
# Posted on: 06-May-2009 09:59:36   

Walaa wrote:

i want to executescaler query that username & password is entered, if it is match with username & Password, it will return UserID.

I thought you needed to select the pswd given the id as you stated before:

i have below query :

Select txtPassword From CMS_Admin where intUserID=1

so now i want to execute this query by using ExecuteScaler()

Anyway, the code should look like the following For Adapter:

IPredicateExpression filter = new PredicateExpression();
filter.Add(CmsAdminFields.UserName == username);
filter.Add(CmsAdminFields.Password == pswd);

DataAccessAdapter adapter = new DataAccessAdapter();
int id = (int)adapter.GetScalar(CmsAdminFields.UserId, null, null, filter);

For SelfServicing:

IPredicateExpression filter = new PredicateExpression();
filter.Add(CmsAdminFields.UserName == username);
filter.Add(CmsAdminFields.Password == pswd);

CmsAdminCollection col = new CmsAdminCollection();
int id = (int)col.GetScalar(CmsAdminFields.UserId, null, null, filter);

Thanks Walaa,

now it is working.

i cleared lot of misunderstanding from your example.

Thanks for your help.

smile