Results 1 to 7 of 7

Thread: Sql insert value using a variable from an inputbox

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2017
    Posts
    165

    Sql insert value using a variable from an inputbox

    How can a I use SQL INSERT statement using a variable from an InputBox in the VALUES of the SQL INSERT. I am using the following code but is not working. Thank you.

    Code:
    Dim ctlPedidoNo As Integer = InputBox("Please enter a Connection String", "CONNECTION STRING")
    
            cmd.CommandText = "INSERT INTO SeguimientoPedidos(PedidoNo) VALUES ('ctlPedidoNo')"

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,301

    Re: Sql insert value using a variable from an inputbox

    This is a VB.NET question so it belongs in VB.NET, not Other Languages. You might be able to make an argument for Database Development but it is definitely a VB.NET question. I have asked the mods to move this thread.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2017
    Posts
    165

    Re: Sql insert value using a variable from an inputbox

    Thank you.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,301

    Re: Sql insert value using a variable from an inputbox

    As for the question, you're not making a lot of sense. Your InputBox is asking the user for a connection string and then assigning the result to an Integer variable. Did you actually mean to prompt them for an ID?

    As for how to use ADO.NET, I suggest that you follow the Database FAQ link in my signature below and follow some of the relevant links. They include my own ADO.NET code examples that includes setting parameters using variables, which is what you need to do.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jun 2017
    Posts
    165

    Re: Sql insert value using a variable from an inputbox

    Quote Originally Posted by jmcilhinney View Post
    As for the question, you're not making a lot of sense. Your InputBox is asking the user for a connection string and then assigning the result to an Integer variable. Did you actually mean to prompt them for an ID?

    As for how to use ADO.NET, I suggest that you follow the Database FAQ link in my signature below and follow some of the relevant links. They include my own ADO.NET code examples that includes setting parameters using variables, which is what you need to do.
    For a moment lets forget I am using an Inputbox ok ?. How can I use Dim variable like this: the SQL INSERT INTO VALUES (variable) ?.

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: Sql insert value using a variable from an inputbox

    Thread moved to the 'VB.Net' (VB2002 and later) forum

    Quote Originally Posted by ebellounisoft View Post
    For a moment lets forget I am using an Inputbox ok ?. How can I use Dim variable like this: the SQL INSERT INTO VALUES (variable) ?.
    See the second half of jmcilhinney's post... use Parameters, you can see examples etc via our Database FAQ's (there is a link to it in his signature, near the top of mine).

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jun 2017
    Posts
    165

    Re: Sql insert value using a variable from an inputbox

    Ok thanks.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width