Re: How cast result of executescalar to a integer



> I am tring to use execute scalar which returns an object *.
> If I assign result of executescalar to an variable defined as an object *
it
> compiles and runs. But this value is actually an integer and I can not
> figure out how to convert it to an integer.
> I would prefer if I did not need to assign it to object variable at all
but
> assigned it directly to an integer value.
>
> Below is currently what I am doning and I have not found the proper way to
> cast to int.
> Object *leadskip;
> leadskip = cmd->ExecuteScalar();

What kind of object is is cmd?
It cannot be a Command Object in ADO as there is no method called
ExecuteScalar.
It looks like ADO.NET. In that case you have the wrong newsgroup.
This newsgroup is for classic ADO, pre-.NET.
There is another newsgroup specifically for ADO.NET.

Also by the looks of it here
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatasqlclientsqlcommandclassexecutescalartopic.asp

you want something like

int val = (int)cmd->ExecuteScalar():

or

int val = (int)*cmd->ExecuteScalar():

Stephen Howe


.



Relevant Pages

  • Re: datasets and table adapters dissapear from forms randomly!
    ... of the previous questions in this newsgroup before posting yours - always a ... but this is a classic ADO newsgroup. ... This email account is my spam trap so I ...
    (microsoft.public.data.ado)
  • Re: Fields with mixed string/number data
    ... some of the previous questions in this newsgroup before posting yours - ... but this is a classic ADO newsgroup. ... ADO.Net bears very little resemblance to classic ADO so, ... connection string. ...
    (microsoft.public.data.ado)
  • Re: Stored procedure returning multiple recordsets
    ... I have a stored procedure like this (it's the shortest I could come ... The same answer applies to both classic ADO and to ADO.Net: ... some of the previous questions in this newsgroup before posting yours - ... but this is a classic ADO newsgroup. ...
    (microsoft.public.data.ado)
  • Re: Incorrect Syntax Near (table name). why ??
    ... said, I'm in the wrong newsgroup, so I got no good leads. ... but this is a classic ADO newsgroup. ... I havent used sql in a long time, but whats wrong ... This email account is my spam trap so I ...
    (microsoft.public.data.ado)
  • Re: Slow queries
    ... of the previous questions in this newsgroup before posting yours - always a ... but this is a classic ADO newsgroup. ... This email account is my spam trap so I ...
    (microsoft.public.data.ado)