I can't figure out the correct syntax for the code below. In the SqlCommand where it says, "WHERE Description LIKE '% + @SearchNAIC + %' " the statement works if I replace it with "... LIKE '%Leather%'..., But the existing format does not work.
I've tried, LIKE '%@SearhNAIC%' and I've tried just, LIKE @SearchNAIC
I have a TextBox, txtSearch, that I'm trying to use as a "Search" feature or filter to set the parameter for the Select statement, but I can't get any results.
The table has, like 21,000 records, so I'm trying to filter it down with the "search" box before it goes to a DropDownList.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' If Not IsPostBack Then
Dim cmd As New SqlCommand("SELECT Description, Code FROM NAICS WHERE Description LIKE '% + @SearchNAIC + %' ORDER BY Description ASC", New SqlConnection(ConfigurationManager.ConnectionStrings("OJTConnectionString").ConnectionString))
cmd.Parameters.Add("@SearchNAIC", SqlDbType.VarChar).Value = txtSearch.Text
Dim drNAIC As SqlDataReader
drNAIC = cmd.ExecuteReader()
ddlNAICS.DataSource = drNAIC
ddlNAICS.DataTextField = "Description"
ddlNAICS.DataValueField = "Code"