Passing variables in SQL Query
Hi,
Currently i am developing a project in the vb.net 2005,
In that project I have a DataGridView of which is being populated via a table adaptor.
I can populate it with a query where the value is statically assigned in the query.
What I'd like is a textbox where I can type in a variable for the query and then populate the datagridview.
but i am not getting how to pass the text box value to the sql query at runtime.
Re: Passing variables in SQL Query
Firstly you need to change your query. Try something like:
SELECT * FROM a table WHERE (YourField=@variable)
Now, when you fill the tableadapter you will need to specify the "@variable",
Me.YourTableAdapter.Fill(YourDataSet.TableName, stValueFromTextBox)
Where fill is your query name, just set the value from the text box to a string, then put the string name in.
Re: Passing variables in SQL Query
Hi,
you can do it by using the following code,
use the following query to pass,
'get records from the customer table
Dim commandString As String = _
"Select * from Customer WHERE Custid =" & TextBox1.Text.ToString & ""
Hope this will help you.