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')"
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.
Re: Sql insert value using a variable from an inputbox
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.
Re: Sql insert value using a variable from an inputbox
Quote:
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) ?.
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
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).
Re: Sql insert value using a variable from an inputbox