Home All Groups Group Topic Archive Search About
Author
27 Aug 2006 3:43 PM
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

Author
27 Aug 2006 3:58 PM
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.


Show quoteHide quote
"Agnes" <ag***@dynamictech.com.hk> wrote in message
news:ed4r%239eyGHA.4972@TK2MSFTNGP03.phx.gbl...
>                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
>
>
Author
28 Aug 2006 9:35 PM
GhostInAK
Hello Scott M.,

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

-Boo

Show quoteHide quote
> 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.
>
> "Agnes" <ag***@dynamictech.com.hk> wrote in message
> news:ed4r%239eyGHA.4972@TK2MSFTNGP03.phx.gbl...
>
>> 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
Author
28 Aug 2006 10:21 PM
Scott M.
Oops!  My bad, you are right.


Show quoteHide quote
"GhostInAK" <ghosti***@gmail.com> wrote in message
news:be1391bf15a428c898bdf9e36086@news.microsoft.com...
> Hello Scott M.,
>
> Just a quick point.. .ExecuteScalar returns an Object, not an Integer.
> .ExecuteNonQuery returns an Integer.
>
> -Boo
>
>> 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.
>>
>> "Agnes" <ag***@dynamictech.com.hk> wrote in message
>> news:ed4r%239eyGHA.4972@TK2MSFTNGP03.phx.gbl...
>>
>>> 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
>
>
Author
27 Aug 2006 4:06 PM
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

Show quoteHide quote
"Agnes" <ag***@dynamictech.com.hk> schreef in bericht
news:ed4r%239eyGHA.4972@TK2MSFTNGP03.phx.gbl...
>                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
>
>
Author
27 Aug 2006 4:20 PM
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.


Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:%231bdgKfyGHA.4392@TK2MSFTNGP04.phx.gbl...
> 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
>
> "Agnes" <ag***@dynamictech.com.hk> schreef in bericht
> news:ed4r%239eyGHA.4972@TK2MSFTNGP03.phx.gbl...
>>                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
>>
>>
>
>
Author
27 Aug 2006 5:07 PM
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

Show quoteHide quote
"Scott M." <s-mar@nospam.nospam> schreef in bericht
news:OysK5QfyGHA.4972@TK2MSFTNGP03.phx.gbl...
> 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.
>
>
> "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
> news:%231bdgKfyGHA.4392@TK2MSFTNGP04.phx.gbl...
>> 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
>>
>> "Agnes" <ag***@dynamictech.com.hk> schreef in bericht
>> news:ed4r%239eyGHA.4972@TK2MSFTNGP03.phx.gbl...
>>>                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
>>>
>>>
>>
>>
>
>
Author
27 Aug 2006 8:16 PM
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.


Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:%23ruohsfyGHA.4044@TK2MSFTNGP04.phx.gbl...
> 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
>
> "Scott M." <s-mar@nospam.nospam> schreef in bericht
> news:OysK5QfyGHA.4972@TK2MSFTNGP03.phx.gbl...
>> 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.
>>
>>
>> "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
>> news:%231bdgKfyGHA.4392@TK2MSFTNGP04.phx.gbl...
>>> 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
>>>
>>> "Agnes" <ag***@dynamictech.com.hk> schreef in bericht
>>> news:ed4r%239eyGHA.4972@TK2MSFTNGP03.phx.gbl...
>>>>                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
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Author
27 Aug 2006 10:22 PM
Branco Medeiros
Cor Ligthert [MVP] wrote:
> 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.
Author
28 Aug 2006 1:04 AM
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.


Show quoteHide quote
"Branco Medeiros" <branco.medei***@gmail.com> wrote in message
news:1156717373.061355.154790@74g2000cwt.googlegroups.com...
> Cor Ligthert [MVP] wrote:
>> 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.
>
Author
28 Aug 2006 2:43 AM
Cor Ligthert [MVP]
Branco,

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

Cor

Show quoteHide quote
"Branco Medeiros" <branco.medei***@gmail.com> schreef in bericht
news:1156717373.061355.154790@74g2000cwt.googlegroups.com...
> Cor Ligthert [MVP] wrote:
>> 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.
>