Missing operand

A

Agnes

Dim authCommand As String = "select count(*) as iRowCount
from coinfo where loginid = @cocode and ((curr_pwd = @pwd and effdate >
getdate()) or (eff_pwd = @pwd and effdate <= getdate()))"
Dim oleCommand As New OleDbCommand(authCommand,
authConnection)

oleCommand.Parameters.Add(New OleDbParameter("@cocode",
OleDbType.VarChar, 10))
oleCommand.Parameters("@cocode").Value = UserName
oleCommand.Parameters.Add(New OleDbParameter("@pwd",
OleDbType.VarChar, 50))
oleCommand.Parameters("@pwd").Value = UserPassword

Dim iCount As Integer = CType(oleCommand.ExecuteScalar(),
Integer) <--- error
It said "Missing operand" . Please help
 
S

Scott M.

Well, you shouldn't need to CType the ExcecuteScalar function call because
ExcecuteScalar returns an integer anyway. But, if your command being
executed causes an exception, ExcecuteScalar may be the root of that.

Put your code in a Try...Catch and see if (and by stepping the code) and
where an exception is occuring.
 
C

Cor Ligthert [MVP]

Agnes,

The OleDBcommand does AFAIK not use named parameters, therefore are it 3
paremeters, you are offering however only 2. Change the names as @Code just
for ?, than you will see it mabye better.

The documentation about this is not always well on MSDN, it is changed, but
the old ones are not deleted.

Cor
 
S

Scott M.

Yes Cor, oleDBCommand *can* work with named parameters, but the names must
be in the same order as the parameters are in the parameters collection of
the command itself.
 
C

Cor Ligthert [MVP]

Scott,

I know that you can use them, but in OleDB you can set everything you want
in that place, even a question mark. In the parameters you can than set a
simple "" or whatever you want.

Cor
 
S

Scott M.

You can create a parameter and set all of its properties (OleDbType, Name,
Length, Precision, etc.) and all of these will be enforced come
ExecuteCommand time. The actual name @something referenced in the
CommandText is ignored though. Only the amount and order of the parameters
are what is used.
 
B

Branco Medeiros

Cor said:
Agnes,

The OleDBcommand does AFAIK not use named parameters, therefore are it 3
paremeters, you are offering however only 2.
<snip>

And then Scott M. argued:
Yes Cor, oleDBCommand *can* work with named parameters, but the names must
be in the same order as the parameters are in the parameters collection of
the command itself.

So if I understand you both correctly, the solution to the OP's problem
would be in the lines of:

<code>
Dim authCommand As String = "select count(*) as iRowCount " _
& "from coinfo where loginid = @p1 " _
& "and ((curr_pwd = @p2 and effdate > getdate()) " _
& "or (eff_pwd = @p3 and effdate <= getdate()))"

Dim oleCommand As New OleDbCommand(authCommand, authConnection)

oleCommand.Parameters.Add(New OleDbParameter("@p1", _
OleDbType.VarChar, 10)).Value = UserName

oleCommand.Parameters.Add(New OleDbParameter("@p2", _
OleDbType.VarChar, 50)).Value = UserPassword

oleCommand.Parameters.Add(New OleDbParameter("@p3", _
OleDbType.VarChar, 50)).Value = UserPassword

Dim iCount As Integer = oleCommand.ExecuteScalar()
</code>

Is this right?

Regards,

Branco.
 
S

Scott M.

I don't know. I was just letting Cor know about the use of the
OleDbParameters. I still think that the problem would be more traceable if
the code were in a try catch that contained a catch for an OleDbException as
well as an Exception.
 
C

Cor Ligthert [MVP]

Branco,

I have not really checked it complete, but in principle. Yes.

Cor
 
G

GhostInAK

Hello Scott M.,

Just a quick point.. .ExecuteScalar returns an Object, not an Integer. .ExecuteNonQuery
returns an Integer.

-Boo
 
S

Scott M.

Oops! My bad, you are right.


GhostInAK said:
Hello Scott M.,

Just a quick point.. .ExecuteScalar returns an Object, not an Integer.
.ExecuteNonQuery returns an Integer.

-Boo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

vfp oledbcommand [Fail] 4
Ole db Command 2
Fail to use oledbparameter 3
oledbparameter 1

Top