Results 1 to 3 of 3

Thread: Passing variables in SQL Query

  1. #1
    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.

  2. #2
    Join Date
    Oct 2005
    Posts
    2,393

    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.

  3. #3
    Join Date
    May 2008
    Posts
    2,297

    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.

Similar Threads

  1. Want to make query dependent on another query.
    By MACE in forum Software Development
    Replies: 4
    Last Post: 01-02-2010, 05:22 PM
  2. Passing variables using iframes
    By Sayam in forum Software Development
    Replies: 3
    Last Post: 07-08-2009, 12:20 PM
  3. Turn on MySQL query cache to speed up query performance
    By DMA2Superman in forum Software Development
    Replies: 3
    Last Post: 07-07-2009, 10:26 AM
  4. Use variables in a MySQL query
    By Chrisch in forum Software Development
    Replies: 3
    Last Post: 25-04-2009, 12:11 PM
  5. Passing variables from one page to another In PHP
    By kaartik in forum Software Development
    Replies: 2
    Last Post: 24-01-2009, 09:28 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,544,373.92049 seconds with 17 queries