vfp oledbcommand [Fail]

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

    #1

    vfp oledbcommand [Fail]

    Dim authConnection As New OleDbConnection ("Provider =
    VfpOleDB.1;Data Source = d:\cgl\vfpmaste r\ttsdata\tts.d bc")
    authConnection. Open()
    Dim authCommand As String = "select loginid from coinfo
    where loginid = @cocode "

    oleCommand.Para meters.Add("@co code", OleDbType.VarCh ar,
    10).Value = "1001"
    or oleCommand.Para meters.Add(new oledbparameter( "@cocode",
    OleDbType.VarCh ar, 10)).Value = "1001"
    Dim drRv As OleDbDataReader =
    oleCommand.Exec uteReader <---ERROR

    Please help, I don't know what's wrong with my statment.
    For the same syntax, I can run very well in my sql server,
    However, When I change into oleddb command.
    I got "missing operand" error.





  • Cor Ligthert [MVP]

    #2
    Re: vfp oledbcommand [Fail]

    Agnes,

    What is the meaning from this boolean code that you are using?

    oleCommand.Para meters.Add("@co code", OleDbType.VarCh ar,
    10).Value = "1001"
    or oleCommand.Para meters.Add(new oledbparameter( "@cocode",
    OleDbType.VarCh ar, 10)).Value = "1001"


    In my idea does it nothing

    Cor

    "Agnes" <agnes@dynamict ech.com.hkschre ef in bericht
    news:uAQUNOsyGH A.3512@TK2MSFTN GP04.phx.gbl...
    Dim authConnection As New OleDbConnection ("Provider =
    VfpOleDB.1;Data Source = d:\cgl\vfpmaste r\ttsdata\tts.d bc")
    authConnection. Open()
    Dim authCommand As String = "select loginid from coinfo
    where loginid = @cocode "
    >
    oleCommand.Para meters.Add("@co code", OleDbType.VarCh ar,
    10).Value = "1001"
    or oleCommand.Para meters.Add(new oledbparameter( "@cocode",
    OleDbType.VarCh ar, 10)).Value = "1001"
    Dim drRv As OleDbDataReader =
    oleCommand.Exec uteReader <---ERROR
    >
    Please help, I don't know what's wrong with my statment.
    For the same syntax, I can run very well in my sql server,
    However, When I change into oleddb command.
    I got "missing operand" error.
    >
    >
    >
    >
    >

    Comment

    • Agnes

      #3
      Re: vfp oledbcommand [Fail]

      I want to pass the company code '1001' as parameter to the command text.

      "Cor Ligthert [MVP]" <notmyfirstname @planet.nl¼¶¼g© ó¶l¥ó·s»D:%23mb bXNzyGHA.5048@T K2MSFTNGP05.phx .gbl...
      Agnes,
      >
      What is the meaning from this boolean code that you are using?
      >
      oleCommand.Para meters.Add("@co code", OleDbType.VarCh ar,
      10).Value = "1001"
      or oleCommand.Para meters.Add(new oledbparameter( "@cocode",
      OleDbType.VarCh ar, 10)).Value = "1001"
      >
      >
      In my idea does it nothing
      >
      Cor
      >
      "Agnes" <agnes@dynamict ech.com.hkschre ef in bericht
      news:uAQUNOsyGH A.3512@TK2MSFTN GP04.phx.gbl...
      > Dim authConnection As New OleDbConnection ("Provider =
      >VfpOleDB.1;Dat a Source = d:\cgl\vfpmaste r\ttsdata\tts.d bc")
      > authConnection. Open()
      > Dim authCommand As String = "select loginid from coinfo
      >where loginid = @cocode "
      >>
      > oleCommand.Para meters.Add("@co code", OleDbType.VarCh ar,
      >10).Value = "1001"
      >or oleCommand.Para meters.Add(new oledbparameter( "@cocode",
      >OleDbType.VarC har, 10)).Value = "1001"
      > Dim drRv As OleDbDataReader =
      >oleCommand.Exe cuteReader <---ERROR
      >>
      >Please help, I don't know what's wrong with my statment.
      >For the same syntax, I can run very well in my sql server,
      >However, When I change into oleddb command.
      >I got "missing operand" error.
      >>
      >>
      >>
      >>
      >>
      >
      >

      Comment

      • Cor Ligthert [MVP]

        #4
        Re: vfp oledbcommand [Fail]

        Brrrrrrrrr

        That or is in your message is no code but a seperator of two possibilities.

        An error that mostly is done by OleDB is that there are added to many times
        a paramaeter.

        If you add it than you add it to an array, that array it is using. Therefore
        you should only add them one time and than change the value as often as you
        want.

        Have a look at this page how to use OleDB parameters.



        I hope this helps,

        Cor


        "Agnes" <agnes@dynamict ech.com.hkschre ef in bericht
        news:%23$vXWb0y GHA.4968@TK2MSF TNGP05.phx.gbl. ..
        >I want to pass the company code '1001' as parameter to the command text.
        >
        "Cor Ligthert [MVP]" <notmyfirstname @planet.nl>
        ¼¶¼g©ó¶l¥ó·s»D: %23mbbXNzyGHA.5 048@TK2MSFTNGP0 5.phx.gbl...
        >Agnes,
        >>
        >What is the meaning from this boolean code that you are using?
        >>
        > oleCommand.Para meters.Add("@co code", OleDbType.VarCh ar,
        >10).Value = "1001"
        >or oleCommand.Para meters.Add(new oledbparameter( "@cocode",
        >OleDbType.VarC har, 10)).Value = "1001"
        >>
        >>
        >In my idea does it nothing
        >>
        >Cor
        >>
        >"Agnes" <agnes@dynamict ech.com.hkschre ef in bericht
        >news:uAQUNOsyG HA.3512@TK2MSFT NGP04.phx.gbl.. .
        >> Dim authConnection As New OleDbConnection ("Provider =
        >>VfpOleDB.1;Da ta Source = d:\cgl\vfpmaste r\ttsdata\tts.d bc")
        >> authConnection. Open()
        >> Dim authCommand As String = "select loginid from coinfo
        >>where loginid = @cocode "
        >>>
        >> oleCommand.Para meters.Add("@co code", OleDbType.VarCh ar,
        >>10).Value = "1001"
        >>or oleCommand.Para meters.Add(new oledbparameter( "@cocode",
        >>OleDbType.Var Char, 10)).Value = "1001"
        >> Dim drRv As OleDbDataReader =
        >>oleCommand.Ex ecuteReader <---ERROR
        >>>
        >>Please help, I don't know what's wrong with my statment.
        >>For the same syntax, I can run very well in my sql server,
        >>However, When I change into oleddb command.
        >>I got "missing operand" error.
        >>>
        >>>
        >>>
        >>>
        >>>
        >>
        >>
        >
        >

        Comment

        • Cindy Winegarden

          #5
          Re: vfp oledbcommand [Fail]

          Hi Agnes,

          "@" preceding a variable name has a different use in FoxPro than it does in
          SQL Server. This works for me:

          Try

          Dim cn1 As New OleDbConnection ( _
          "Provider=VFPOL EDB.1;Data Source=C:\Temp\ ;")
          cn1.Open()
          '-- Make some VFP data to play with
          Dim cmd1 As New OleDbCommand( _
          "Create Table TestParameter (Field1 C(10))", cn1)
          Dim cmd2 As New OleDbCommand( _
          "Insert Into TestParameter Values ('Hello')", cn1)
          Dim cmd3 As New OleDbCommand( _
          "Insert Into TestParameter Values ('World')", cn1)
          cmd1.ExecuteNon Query()
          cmd2.ExecuteNon Query()
          cmd3.ExecuteNon Query()

          Dim cmd4 As New OleDbCommand( _
          "Select * From TestParameter Where Field1 = ?", cn1)
          Dim p1 As New OleDbParameter( "Field1", "World")
          Dim da1 As New OleDbDataAdapte r(cmd4)
          Dim ds1 As New DataSet
          Dim dr1 As DataRow

          cmd4.Parameters .Add(p1)
          da1.Fill(ds1)
          For Each dr1 In ds1.Tables(0).R ows
          Console.WriteLi ne(dr1.Item(0). ToString())
          Next
          Console.ReadLin e()
          cn1.Close()

          Catch e As Exception
          MsgBox(e.ToStri ng())
          End Try

          --
          Cindy Winegarden MCSD, Microsoft Most Valuable Professional
          cindy@cindywine garden.com


          "Agnes" <agnes@dynamict ech.com.hkwrote in message
          news:uAQUNOsyGH A.3512@TK2MSFTN GP04.phx.gbl...
          Dim authConnection As New OleDbConnection ("Provider =
          VfpOleDB.1;Data Source = d:\cgl\vfpmaste r\ttsdata\tts.d bc")
          authConnection. Open()
          Dim authCommand As String = "select loginid from coinfo
          where loginid = @cocode "
          >
          oleCommand.Para meters.Add("@co code", OleDbType.VarCh ar,
          10).Value = "1001"
          or oleCommand.Para meters.Add(new oledbparameter( "@cocode",
          OleDbType.VarCh ar, 10)).Value = "1001"
          Dim drRv As OleDbDataReader =
          oleCommand.Exec uteReader <---ERROR
          >
          Please help, I don't know what's wrong with my statment.
          For the same syntax, I can run very well in my sql server,
          However, When I change into oleddb command.
          I got "missing operand" error.
          >
          >
          >
          >
          >

          Comment

          Working...