-
May 17th, 2018, 11:07 AM
#1
Thread Starter
Addicted Member
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')"
-
May 17th, 2018, 11:13 AM
#2
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.
-
May 17th, 2018, 11:13 AM
#3
Thread Starter
Addicted Member
Re: Sql insert value using a variable from an inputbox
-
May 17th, 2018, 11:16 AM
#4
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.
-
May 17th, 2018, 11:21 AM
#5
Thread Starter
Addicted Member
Re: Sql insert value using a variable from an inputbox
Originally Posted by jmcilhinney
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) ?.
-
May 17th, 2018, 11:27 AM
#6
Re: Sql insert value using a variable from an inputbox
Thread moved to the 'VB.Net' (VB2002 and later) forum
Originally Posted by ebellounisoft
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).
-
May 17th, 2018, 11:31 AM
#7
Thread Starter
Addicted Member
Re: Sql insert value using a variable from an inputbox
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|