'access sql and the LIKE keyword [duplicate]
I am working on an addin for Visio using Access as a backend database. In one of my forms I am filling a datagridview with parts from a table. In this DGV I wish to include only parts of type "connector" and also filter out connector parts which have the word "banana" (banana connectors) in the description. The line of sql I came up with seemed simple enough, when I execute it in a query window within Access it works as expected. However, when I execute the exact statement within the context of my addin, it still returns the banana connectors! Can anyone tell me what the difference is? Below is the code from my addin. Thanks for any tips
Using con As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & VE_docPath & VE_currentProject & ".accdb;Persist Security Info=True")
Using cmd As New OleDb.OleDbCommand("", con)
Try
sql = "SELECT PartDefID, PartNumber, PartNumberAlt, PartDescription, ShellType, ElementCount, TerminalCount, KitNumber FROM PartDefinitions WHERE PartClass = 1 AND (PartDescription NOT LIKE '*banana*')"
cmd.CommandText = sql
cmd.CommandType = CommandType.Text
cmd.Connection = con
con.Open()
Dim daGet As New OleDbDataAdapter()
daGet.SelectCommand = cmd
daGet.Fill(TableConnector)
Me.PartDefDataGridView.DataSource = TableConnector
If Me.PartDefDataGridView.RowCount > 0 Then
Me.PartDefDataGridView.Columns("PartDefID").Visible = False 'hide this column in the DGV
Me.PartDefDataGridView.ClearSelection()
Me.PartDefDataGridView.Rows(0).Selected = True
End If
Catch SqlError As System.Data.SqlTypes.SqlTypeException
MsgBox(SqlError.Message, MsgBoxStyle.SystemModal, "Error")
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.SystemModal, "Error")
End Try
End Using
End Using
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
