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. Visual Basic
  4. Explanation Parameterised Queries

Explanation Parameterised Queries

Scheduled Pinned Locked Moved Visual Basic
agentic-aiquestionannouncement
6 Posts 2 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.
  • K Offline
    K Offline
    keninfo
    wrote on last edited by
    #1

    Is there anyone who can explain Parameterised Queries. I don't get it where the parameters are related to. How do i write an Updatecommand with parameters, i tried something but it does not work. Dim command As System.Data.OleDb.OleDbCommand = New System.Data.OleDb.OleDbCommand("Update(Agent)" & _ " SET Nummer_Naam = @NummerNaam, Agentnummer = @AgentNummer, Agentnaam = @AgentNaam " & _ " WHERE(Agentnummer = @agentNummerOud)") command.Parameters.Add("@NummerNaam", OleDb.OleDbType.VarChar, 20, "NummerNaam") command.Parameters.Add("@AgentNummer", OleDb.OleDbType.Integer, 10, "AgentNummer") command.Parameters.Add("@AgentNaam", OleDb.OleDbType.VarChar, 20, "AgentNaam") Dim parameter As System.Data.OleDb.OleDbParameter = command.Parameters.Add( _ "@agentNummerOud", OleDb.OleDbType.Integer, 10, "AgentNummer") parameter.SourceVersion = DataRowVersion.Original daAgent.UpdateCommand = command daAgent.Update(dsAgent)

    C 1 Reply Last reply
    0
    • K keninfo

      Is there anyone who can explain Parameterised Queries. I don't get it where the parameters are related to. How do i write an Updatecommand with parameters, i tried something but it does not work. Dim command As System.Data.OleDb.OleDbCommand = New System.Data.OleDb.OleDbCommand("Update(Agent)" & _ " SET Nummer_Naam = @NummerNaam, Agentnummer = @AgentNummer, Agentnaam = @AgentNaam " & _ " WHERE(Agentnummer = @agentNummerOud)") command.Parameters.Add("@NummerNaam", OleDb.OleDbType.VarChar, 20, "NummerNaam") command.Parameters.Add("@AgentNummer", OleDb.OleDbType.Integer, 10, "AgentNummer") command.Parameters.Add("@AgentNaam", OleDb.OleDbType.VarChar, 20, "AgentNaam") Dim parameter As System.Data.OleDb.OleDbParameter = command.Parameters.Add( _ "@agentNummerOud", OleDb.OleDbType.Integer, 10, "AgentNummer") parameter.SourceVersion = DataRowVersion.Original daAgent.UpdateCommand = command daAgent.Update(dsAgent)

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      keninfo wrote:

      i tried something but it does not work.

      What do you mean it doesn't work? Do you want us to guess? My guess would be that you have not supplied the values for the parameters properly (hint: the last argument in Parameters.Add). These are literal values. They will be the same every time the application is run. You might want to change these to the values you want the parameters to have.


      Upcoming events: * Glasgow: SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

      K 1 Reply Last reply
      0
      • C Colin Angus Mackay

        keninfo wrote:

        i tried something but it does not work.

        What do you mean it doesn't work? Do you want us to guess? My guess would be that you have not supplied the values for the parameters properly (hint: the last argument in Parameters.Add). These are literal values. They will be the same every time the application is run. You might want to change these to the values you want the parameters to have.


        Upcoming events: * Glasgow: SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

        K Offline
        K Offline
        keninfo
        wrote on last edited by
        #3

        But i don't know what @AgentNaam corresponse with, it should be a parameter, i guess. Can you explain the following command.Parameters.Add("@AgentNaam", OleDb.OleDbType.VarChar, 20, "AgentNaam") I need to update a table with new values, which are inserted via textfields. I don't get the way from textfield inserting till the actual update I know, it seems stupid that i cannot manage this. But i need some help to start.

        C 1 Reply Last reply
        0
        • K keninfo

          But i don't know what @AgentNaam corresponse with, it should be a parameter, i guess. Can you explain the following command.Parameters.Add("@AgentNaam", OleDb.OleDbType.VarChar, 20, "AgentNaam") I need to update a table with new values, which are inserted via textfields. I don't get the way from textfield inserting till the actual update I know, it seems stupid that i cannot manage this. But i need some help to start.

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          keninfo wrote:

          But i don't know what @AgentNaam corresponse with, it should be a parameter, i guess. Can you explain the following command.Parameters.Add("@AgentNaam", OleDb.OleDbType.VarChar, 20, "AgentNaam")

          Did you not read the documentation? @AgentNaam is your parameter name (think of is as a variable name). When you use @AgentNaam in your SQL you get the value of the parameter. Just like you would a variable in VB.NET The last argument is the value you want the parameter to have. Putting in "AgentNaam" will mean the parameter will always have that value. It is like writing the following in VB.NET: Dim agentNaam As String = "AgentNaam"

          keninfo wrote:

          I need to update a table with new values, which are inserted via textfields. I don't get the way from textfield inserting till the actual update

          Where you currently have the literal string values (That's the last argument of the Add method) you should change that to the appropriate values that have come from the text boxes.


          Upcoming events: * Glasgow: SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

          K 1 Reply Last reply
          0
          • C Colin Angus Mackay

            keninfo wrote:

            But i don't know what @AgentNaam corresponse with, it should be a parameter, i guess. Can you explain the following command.Parameters.Add("@AgentNaam", OleDb.OleDbType.VarChar, 20, "AgentNaam")

            Did you not read the documentation? @AgentNaam is your parameter name (think of is as a variable name). When you use @AgentNaam in your SQL you get the value of the parameter. Just like you would a variable in VB.NET The last argument is the value you want the parameter to have. Putting in "AgentNaam" will mean the parameter will always have that value. It is like writing the following in VB.NET: Dim agentNaam As String = "AgentNaam"

            keninfo wrote:

            I need to update a table with new values, which are inserted via textfields. I don't get the way from textfield inserting till the actual update

            Where you currently have the literal string values (That's the last argument of the Add method) you should change that to the appropriate values that have come from the text boxes.


            Upcoming events: * Glasgow: SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

            K Offline
            K Offline
            keninfo
            wrote on last edited by
            #5

            Thanks for the reply, Ok, can i use it like this? command.Parameters.Add("@AgentNaam", OleDb.OleDbType.VarChar, 20, txtAgentNummer.Text) If so, why is my table not updated after? parameter.SourceVersion = DataRowVersion.Original daAgent.UpdateCommand = command daAgent.Update(dsAgent)

            C 1 Reply Last reply
            0
            • K keninfo

              Thanks for the reply, Ok, can i use it like this? command.Parameters.Add("@AgentNaam", OleDb.OleDbType.VarChar, 20, txtAgentNummer.Text) If so, why is my table not updated after? parameter.SourceVersion = DataRowVersion.Original daAgent.UpdateCommand = command daAgent.Update(dsAgent)

              C Offline
              C Offline
              Colin Angus Mackay
              wrote on last edited by
              #6

              Why are you using a data adapter? command.ExecuteNonQuery() is all you need (and an open connection)


              Upcoming events: * Glasgow: SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

              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