Same program different question..
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.
Any ideas?
Using variables in SQL QueryUsing variables in SQL Query
Page 1 of 1
7 Replies - 15718 Views - Last Post: 03 May 2010 - 08:20 AM
Replies To: Using variables in SQL Query
#3
Re: Using variables in SQL Query
Posted 12 August 2008 - 10:06 PM
I have a stored procedure that I can manually change:
select * from jobs where status = '2'
What I want to be able to do is use a textbox on my form to change the 2 to whatever is in the textbox.
select * from jobs where status = '2'
What I want to be able to do is use a textbox on my form to change the 2 to whatever is in the textbox.
#4
Re: Using variables in SQL Query
Posted 13 August 2008 - 01:28 AM
Decompile,
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" bit:
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.
this help any?
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" bit:
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.
this help any?
#5
Re: Using variables in SQL Query
Posted 13 August 2008 - 03:33 AM
That's brilliant. Exactly what I was looking for.
Thank you very much.
Thank you very much.
#6
Re: Using variables in SQL Query
Posted 03 December 2008 - 04:50 AM
um can one of you guys explain more on the solution?
With screenshots if can ><
With screenshots if can ><
#7
Re: Using variables in SQL Query
Posted 04 December 2008 - 04:25 AM
DeCompile, on 13 Aug, 2008 - 02:33 AM, said:
That's brilliant. Exactly what I was looking for.
Thank you very much.
Thank you very much.
did this solution worked?can you post the exactly code?
ia m trying to do the same but it works for me only for number values.when i put strings it returns exception that column of the value does not exist.
this is my code.
'get records from the customer table Dim commandString As String = _ "Select * from pelates WHERE CarNumber =" & TextBox1.Text.ToString & ""
Ok problem solved.
This post has been edited by j0e: 04 December 2008 - 04:33 AM
#8 Guest_Rijuls*
Re: Using variables in SQL Query
Posted 03 May 2010 - 08:20 AM
I want a sql query like
SELECT * FROM SYSTWODB_POST
in the above query i want 'SYSTWODB_' or 'SYSTWODB' in a variable name and execute the same successfully... this is for redundancy... Please help to advise....
SELECT * FROM SYSTWODB_POST
in the above query i want 'SYSTWODB_' or 'SYSTWODB' in a variable name and execute the same successfully... this is for redundancy... Please help to advise....
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote






|