Using variables in SQL Query

Using variables in SQL Query

Page 1 of 1

7 Replies - 23355 Views - Last Post: 03 May 2010 - 08:20 AM Rate Topic: -----

#1 DeCompile  Icon User is offline

  • D.I.C Regular

Reputation: 19
  • View blog
  • Posts: 301
  • Joined: 20-July 08

Using variables in SQL Query

Post icon  Posted 12 August 2008 - 09:29 PM

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?
Is This A Good Question/Topic? 0
  • +

Replies To: Using variables in SQL Query

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Using variables in SQL Query

Posted 12 August 2008 - 09:44 PM

Stored Procedure.
Was This Post Helpful? 0
  • +
  • -

#3 DeCompile  Icon User is offline

  • D.I.C Regular

Reputation: 19
  • View blog
  • Posts: 301
  • Joined: 20-July 08

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.
Was This Post Helpful? 0
  • +
  • -

#4 dangerkeepoff  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 18
  • Joined: 02-July 08

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?
Was This Post Helpful? 0
  • +
  • -

#5 DeCompile  Icon User is offline

  • D.I.C Regular

Reputation: 19
  • View blog
  • Posts: 301
  • Joined: 20-July 08

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.
Was This Post Helpful? 0
  • +
  • -

#6 noveus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 01-December 08

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 ><
Was This Post Helpful? 0
  • +
  • -

#7 j0e  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 46
  • Joined: 01-June 08

Re: Using variables in SQL Query

Posted 04 December 2008 - 04:25 AM

View PostDeCompile, on 13 Aug, 2008 - 02:33 AM, said:

That's brilliant. Exactly what I was looking for.

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

Was This Post Helpful? 0
  • +
  • -

#8 Guest_Rijuls*


Reputation:

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....
Was This Post Helpful? 0

Page 1 of 1