Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. passing a parameter into a select command

passing a parameter into a select command

Scheduled Pinned Locked Moved C#
help
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rmokkenstorm
    wrote on last edited by
    #1

    i build something like a search function. but he doesn't fill my parameter the parameter does get a value.. but when he should put it into my select command he give the error: No value given for one or more required parameters. so.. this is a little peace of my select command WHERE (T075_BORGTOCHTNUMMER_1 LIKE VAL) en this is my code that should fill the parameter "VAL" string val; if (textBox1.Text != string.Empty) { val = textBox1.Text; } else { val = "%"; } this.dBANBM_T075_BORGTOCHTTableAdapter.Fill(this.testdb1DataSet.DBANBM_T075_BORGTOCHT); hope some one can help or give some advise

    W 1 Reply Last reply
    0
    • R Rmokkenstorm

      i build something like a search function. but he doesn't fill my parameter the parameter does get a value.. but when he should put it into my select command he give the error: No value given for one or more required parameters. so.. this is a little peace of my select command WHERE (T075_BORGTOCHTNUMMER_1 LIKE VAL) en this is my code that should fill the parameter "VAL" string val; if (textBox1.Text != string.Empty) { val = textBox1.Text; } else { val = "%"; } this.dBANBM_T075_BORGTOCHTTableAdapter.Fill(this.testdb1DataSet.DBANBM_T075_BORGTOCHT); hope some one can help or give some advise

      W Offline
      W Offline
      WillemM
      wrote on last edited by
      #2

      It depends on what database you use, but normally you can create commands like this: SELECT * FROM DBANBM_T075_BORGTOCHT WHERE Id = @Id And insert parameters into the command like this: SqlCommand cmd = new SqlCommand(query,connection); cmd.AddParameterWithValue("@Id",1); Be adviced: I do this without the help of a little intellisense ;P So the syntax of the AddParameterWithValue may vary. WM.
      What about weapons of mass-construction? -- modified at 3:33 Wednesday 10th May, 2006 For an access database the parameters have a questionmark as placeholder and are position dependend.

      R 1 Reply Last reply
      0
      • W WillemM

        It depends on what database you use, but normally you can create commands like this: SELECT * FROM DBANBM_T075_BORGTOCHT WHERE Id = @Id And insert parameters into the command like this: SqlCommand cmd = new SqlCommand(query,connection); cmd.AddParameterWithValue("@Id",1); Be adviced: I do this without the help of a little intellisense ;P So the syntax of the AddParameterWithValue may vary. WM.
        What about weapons of mass-construction? -- modified at 3:33 Wednesday 10th May, 2006 For an access database the parameters have a questionmark as placeholder and are position dependend.

        R Offline
        R Offline
        Rmokkenstorm
        wrote on last edited by
        #3

        i use a access database and soon i will use a oracle database. but what do you mean with "are position dependend"?

        W 1 Reply Last reply
        0
        • R Rmokkenstorm

          i use a access database and soon i will use a oracle database. but what do you mean with "are position dependend"?

          W Offline
          W Offline
          WillemM
          wrote on last edited by
          #4

          If you have INSERT INTO Tbl (Id,Value) (?,?) The first parameter to add has to be the parameter that is first mentioned in the command. You cant first add the parameter for the Value and the parameter for Id after that. WM.
          What about weapons of mass-construction?

          R 1 Reply Last reply
          0
          • W WillemM

            If you have INSERT INTO Tbl (Id,Value) (?,?) The first parameter to add has to be the parameter that is first mentioned in the command. You cant first add the parameter for the Value and the parameter for Id after that. WM.
            What about weapons of mass-construction?

            R Offline
            R Offline
            Rmokkenstorm
            wrote on last edited by
            #5

            oh i see thanks error: Syntax error (missing operator) in query expression '(T075_BORGTOCHTNUMMER_1 = ?VAL)'. what operator does he need? i've tried '' and [] and stuf like that. the other code i didn't change.

            S 1 Reply Last reply
            0
            • R Rmokkenstorm

              oh i see thanks error: Syntax error (missing operator) in query expression '(T075_BORGTOCHTNUMMER_1 = ?VAL)'. what operator does he need? i've tried '' and [] and stuf like that. the other code i didn't change.

              S Offline
              S Offline
              Stefan Troschuetz
              wrote on last edited by
              #6

              Use this expression: '(T075_BORGTOCHTNUMMER_1 = ?)'. In Access you can't name the parameters. Thats the reason you have to add their values in the right order.


              "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

              www.troschuetz.de

              R 1 Reply Last reply
              0
              • S Stefan Troschuetz

                Use this expression: '(T075_BORGTOCHTNUMMER_1 = ?)'. In Access you can't name the parameters. Thats the reason you have to add their values in the right order.


                "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

                www.troschuetz.de

                R Offline
                R Offline
                Rmokkenstorm
                wrote on last edited by
                #7

                No value given for one or more required parameters. how do i set the value of my textbox to this parameter?

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups