Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Passing variables in SQL Query

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 01-01-2009
Member
 
Join Date: Dec 2008
Posts: 12
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.

Reply With Quote
  #2  
Old 01-01-2009
Member
 
Join Date: Oct 2005
Posts: 2,387
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.
Reply With Quote
  #3  
Old 01-01-2009
Member
 
Join Date: May 2008
Posts: 2,286
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Passing variables in SQL Query"
Thread Thread Starter Forum Replies Last Post
Want to make query dependent on another query. MACE Software Development 4 01-02-2010 04:22 PM
Passing variables using iframes Sayam Software Development 3 07-08-2009 12:20 PM
Turn on MySQL query cache to speed up query performance DMA2Superman Software Development 3 07-07-2009 10:26 AM
Use variables in a MySQL query Chrisch Software Development 3 25-04-2009 12:11 PM
Passing variables from one page to another In PHP kaartik Software Development 2 24-01-2009 08:28 PM


All times are GMT +5.5. The time now is 08:36 AM.