Missing operand

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Agnes

    #1

    Missing operand

    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(au thCommand,
    authConnection)

    oleCommand.Para meters.Add(New OleDbParameter( "@cocode",
    OleDbType.VarCh ar, 10))
    oleCommand.Para meters("@cocode ").Value = UserName
    oleCommand.Para meters.Add(New OleDbParameter( "@pwd",
    OleDbType.VarCh ar, 50))
    oleCommand.Para meters("@pwd"). Value = UserPassword

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


  • Scott M.

    #2
    Re: Missing operand

    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" <agnes@dynamict ech.com.hkwrote in message
    news:ed4r%239ey GHA.4972@TK2MSF TNGP03.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(au thCommand,
    authConnection)
    >
    oleCommand.Para meters.Add(New OleDbParameter( "@cocode",
    OleDbType.VarCh ar, 10))
    oleCommand.Para meters("@cocode ").Value = UserName
    oleCommand.Para meters.Add(New OleDbParameter( "@pwd",
    OleDbType.VarCh ar, 50))
    oleCommand.Para meters("@pwd"). Value = UserPassword
    >
    Dim iCount As Integer = CType(oleComman d.ExecuteScalar (),
    Integer) <--- error
    It said "Missing operand" . Please help
    >
    >

    Comment

    • Cor Ligthert [MVP]

      #3
      Re: Missing operand

      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" <agnes@dynamict ech.com.hkschre ef in bericht
      news:ed4r%239ey GHA.4972@TK2MSF TNGP03.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(au thCommand,
      authConnection)
      >
      oleCommand.Para meters.Add(New OleDbParameter( "@cocode",
      OleDbType.VarCh ar, 10))
      oleCommand.Para meters("@cocode ").Value = UserName
      oleCommand.Para meters.Add(New OleDbParameter( "@pwd",
      OleDbType.VarCh ar, 50))
      oleCommand.Para meters("@pwd"). Value = UserPassword
      >
      Dim iCount As Integer = CType(oleComman d.ExecuteScalar (),
      Integer) <--- error
      It said "Missing operand" . Please help
      >
      >

      Comment

      • Scott M.

        #4
        Re: Missing operand

        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]" <notmyfirstname @planet.nlwrote in message
        news:%231bdgKfy GHA.4392@TK2MSF TNGP04.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" <agnes@dynamict ech.com.hkschre ef in bericht
        news:ed4r%239ey GHA.4972@TK2MSF TNGP03.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(au thCommand,
        >authConnection )
        >>
        > oleCommand.Para meters.Add(New OleDbParameter( "@cocode",
        >OleDbType.VarC har, 10))
        > oleCommand.Para meters("@cocode ").Value = UserName
        > oleCommand.Para meters.Add(New OleDbParameter( "@pwd",
        >OleDbType.VarC har, 50))
        > oleCommand.Para meters("@pwd"). Value = UserPassword
        >>
        > Dim iCount As Integer = CType(oleComman d.ExecuteScalar (),
        >Integer) <--- error
        >It said "Missing operand" . Please help
        >>
        >>
        >
        >

        Comment

        • Cor Ligthert [MVP]

          #5
          Re: Missing operand

          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.nosp amschreef in bericht
          news:OysK5QfyGH A.4972@TK2MSFTN GP03.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]" <notmyfirstname @planet.nlwrote in message
          news:%231bdgKfy GHA.4392@TK2MSF TNGP04.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" <agnes@dynamict ech.com.hkschre ef in bericht
          >news:ed4r%239e yGHA.4972@TK2MS FTNGP03.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(au thCommand,
          >>authConnectio n)
          >>>
          >> oleCommand.Para meters.Add(New OleDbParameter( "@cocode",
          >>OleDbType.Var Char, 10))
          >> oleCommand.Para meters("@cocode ").Value = UserName
          >> oleCommand.Para meters.Add(New OleDbParameter( "@pwd",
          >>OleDbType.Var Char, 50))
          >> oleCommand.Para meters("@pwd"). Value = UserPassword
          >>>
          >> Dim iCount As Integer = CType(oleComman d.ExecuteScalar (),
          >>Integer) <--- error
          >>It said "Missing operand" . Please help
          >>>
          >>>
          >>
          >>
          >
          >

          Comment

          • Scott M.

            #6
            Re: Missing operand

            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.


            "Cor Ligthert [MVP]" <notmyfirstname @planet.nlwrote in message
            news:%23ruohsfy GHA.4044@TK2MSF TNGP04.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.nosp amschreef in bericht
            news:OysK5QfyGH A.4972@TK2MSFTN GP03.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]" <notmyfirstname @planet.nlwrote in message
            >news:%231bdgKf yGHA.4392@TK2MS FTNGP04.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" <agnes@dynamict ech.com.hkschre ef in bericht
            >>news:ed4r%239 eyGHA.4972@TK2M SFTNGP03.phx.gb l...
            >>> 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(au thCommand,
            >>>authConnecti on)
            >>>>
            >>> oleCommand.Para meters.Add(New OleDbParameter( "@cocode",
            >>>OleDbType.Va rChar, 10))
            >>> oleCommand.Para meters("@cocode ").Value = UserName
            >>> oleCommand.Para meters.Add(New OleDbParameter( "@pwd",
            >>>OleDbType.Va rChar, 50))
            >>> oleCommand.Para meters("@pwd"). Value = UserPassword
            >>>>
            >>> Dim iCount As Integer =
            >>>CType(oleCom mand.ExecuteSca lar(), Integer) <--- error
            >>>It said "Missing operand" . Please help
            >>>>
            >>>>
            >>>
            >>>
            >>
            >>
            >
            >

            Comment

            • Branco Medeiros

              #7
              Re: Missing operand

              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(au thCommand, authConnection)

              oleCommand.Para meters.Add(New OleDbParameter( "@p1", _
              OleDbType.VarCh ar, 10)).Value = UserName

              oleCommand.Para meters.Add(New OleDbParameter( "@p2", _
              OleDbType.VarCh ar, 50)).Value = UserPassword

              oleCommand.Para meters.Add(New OleDbParameter( "@p3", _
              OleDbType.VarCh ar, 50)).Value = UserPassword

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

              Is this right?

              Regards,

              Branco.

              Comment

              • Scott M.

                #8
                Re: Missing operand

                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.


                "Branco Medeiros" <branco.medeiro s@gmail.comwrot e in message
                news:1156717373 .061355.154790@ 74g2000cwt.goog legroups.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(au thCommand, authConnection)
                >
                oleCommand.Para meters.Add(New OleDbParameter( "@p1", _
                OleDbType.VarCh ar, 10)).Value = UserName
                >
                oleCommand.Para meters.Add(New OleDbParameter( "@p2", _
                OleDbType.VarCh ar, 50)).Value = UserPassword
                >
                oleCommand.Para meters.Add(New OleDbParameter( "@p3", _
                OleDbType.VarCh ar, 50)).Value = UserPassword
                >
                Dim iCount As Integer = oleCommand.Exec uteScalar()
                </code>
                >
                Is this right?
                >
                Regards,
                >
                Branco.
                >

                Comment

                • Cor Ligthert [MVP]

                  #9
                  Re: Missing operand

                  Branco,

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

                  Cor

                  "Branco Medeiros" <branco.medeiro s@gmail.comschr eef in bericht
                  news:1156717373 .061355.154790@ 74g2000cwt.goog legroups.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(au thCommand, authConnection)
                  >
                  oleCommand.Para meters.Add(New OleDbParameter( "@p1", _
                  OleDbType.VarCh ar, 10)).Value = UserName
                  >
                  oleCommand.Para meters.Add(New OleDbParameter( "@p2", _
                  OleDbType.VarCh ar, 50)).Value = UserPassword
                  >
                  oleCommand.Para meters.Add(New OleDbParameter( "@p3", _
                  OleDbType.VarCh ar, 50)).Value = UserPassword
                  >
                  Dim iCount As Integer = oleCommand.Exec uteScalar()
                  </code>
                  >
                  Is this right?
                  >
                  Regards,
                  >
                  Branco.
                  >

                  Comment

                  • GhostInAK

                    #10
                    Re: Missing operand

                    Hello Scott M.,

                    Just a quick point.. .ExecuteScalar returns an Object, not an Integer. .ExecuteNonQuer y
                    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" <agnes@dynamict ech.com.hkwrote in message
                    news:ed4r%239ey GHA.4972@TK2MSF TNGP03.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(au thCommand,
                    >authConnection )
                    >oleCommand.Par ameters.Add(New OleDbParameter( "@cocode",
                    >OleDbType.VarC har, 10)) oleCommand.Para meters("@cocode ").Value =
                    >UserName oleCommand.Para meters.Add(New OleDbParameter( "@pwd",
                    >OleDbType.VarC har, 50)) oleCommand.Para meters("@pwd"). Value =
                    >UserPassword
                    >>
                    >Dim iCount As Integer = CType(oleComman d.ExecuteScalar (),
                    >Integer) <--- error
                    >It said "Missing operand" . Please help

                    Comment

                    • Scott M.

                      #11
                      Re: Missing operand

                      Oops! My bad, you are right.


                      "GhostInAK" <ghostinak@gmai l.comwrote in message
                      news:be1391bf15 a428c898bdf9e36 086@news.micros oft.com...
                      Hello Scott M.,
                      >
                      Just a quick point.. .ExecuteScalar returns an Object, not an Integer.
                      .ExecuteNonQuer y 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" <agnes@dynamict ech.com.hkwrote in message
                      >news:ed4r%239e yGHA.4972@TK2MS FTNGP03.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(au thCommand,
                      >>authConnectio n)
                      >>oleCommand.Pa rameters.Add(Ne w OleDbParameter( "@cocode",
                      >>OleDbType.Var Char, 10)) oleCommand.Para meters("@cocode ").Value =
                      >>UserName oleCommand.Para meters.Add(New OleDbParameter( "@pwd",
                      >>OleDbType.Var Char, 50)) oleCommand.Para meters("@pwd"). Value =
                      >>UserPasswor d
                      >>>
                      >>Dim iCount As Integer = CType(oleComman d.ExecuteScalar (),
                      >>Integer) <--- error
                      >>It said "Missing operand" . Please help
                      >
                      >

                      Comment

                      Working...