none
Need help with a query using a Textbox RRS feed

  • Question

  • I have a working SQL Select Query in my application with a search condition taken from a textbox control value in my aplication's form.

     

    Below is my code:

     

    Code Block

    Dim Query2 As SqlCommand = New SqlCommand("Select * from table1 with(nolock) where field1 like '" & TextBox1.Text & "%'", SqlConnection1)
    Query2.CommandTimeout = 300

     

     

    What I want to do is to only get the first 5 characters from the textbox value as the search condition for my query, for example, if the user entered aabbccdd how can I make it work so that only the values aabbc is passed as the search condition for the query?

     

    Any ideas would be gladly appreciated.

    Friday, November 23, 2007 5:52 AM

Answers

  • Code Block

    Dim Query2 As SqlCommand = New SqlCommand("Select * from table1 with(nolock) where field1 like '" & TextBox1.Text.Substring(0, 5) & "%'", SqlConnection1)
    Query2.CommandTimeout = 300

     

     

    Adam
    Friday, November 23, 2007 5:56 AM