Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Won't accept SQL LIKE

Status
Not open for further replies.

Stegmite

Programmer
Aug 18, 2004
36
US
I'm trying to filter a datagrid on the fly using this:
Code:
On Page Load...
Dim mySort As String
If Session("Sort") = "" Then
  mySort = "SELECT * FROM Import"
  OleDbDataAdapter1.SelectCommand = New OleDb.OleDbCommand(mySort, OleDbConnection1)
  OleDbDataAdapter1.Fill(dsInv)
  dgInv.DataBind()
Else
  mySort = Session("Sort")
  OleDbDataAdapter1.SelectCommand = New OleDb.OleDbCommand(mySort, OleDbConnection1)
  OleDbDataAdapter1.Fill(dsInv)
  dgInv.DataBind()
End If
and
Code:
On cmdSearch.Click...
Dim vCrit As String = txtCriteria.Text
If cmbCols.SelectedValue = "Description" Then
   If vCrit = "" Then
      Session("Sort") = "SELECT * FROM Import ORDER BY Description"
   Else
      Session("Sort") = "SELECT * FROM Import WHERE Description LIKE '" & vCrit & "' ORDER BY Description"
   End If
End If
Session("Crit") = vCrit
Response.Redirect("inventory.aspx")

However, the LIKE command won't work like it should. Is there anything I can do to make this work?
 
Because your LIKE statement should look more like this:

Code:
WHERE (Description LIKE N'%" & vcrit & "%')
 
The N is MSSQL NChar or NText modifier in your code you should not need it

bassguy
 
Yup. Use the N prefix only when the columns you're comparing against are NCHAR, NVARCHAR, or NTEXT.

Chip H.


____________________________________________________________________
Click here to learn Ways to help with Tsunami Relief
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top