1

The code below works great, and I need it to do more :). It is for vb.net 2008 with access database. At the moment it matches based on paramValue, and needs an exact match. How can I change it to look for a pattern instead?? For example I want anything that contains the text "Fizz" and then "Bom".
--And PLEASE share any link where I can learn about this blend of SQL+access+vb.net. Thank you! Steve

Dim table As New DataTable(tableName)
table.Locale = System.Globalization.CultureInfo.InvariantCulture

Using connection As New OdbcConnection(ConnectionString)
    connection.Open()

    Dim query As String = String.Format("SELECT * FROM [{0}] WHERE [{1}] = ?", _
                                        tableName, _
                                        paramName)
    Dim selectCommand As New OdbcCommand(query, connection)
    selectCommand.Parameters.Add(New OdbcParameter("@" & paramName, paramValue))

    Dim adapter As New OdbcDataAdapter(selectCommand)
    adapter.FillSchema(table, SchemaType.Mapped)
    adapter.Fill(table)
End Using

Return table
3
  • Beware your code is susceptible to SQL injection. Commented Feb 9, 2011 at 12:59
  • @user414564 You should vote up and / or accept answers that are useful to you, because it helps both the person answering and anyone who finds this question in the future. Commented Feb 9, 2011 at 13:14
  • Thanks. LOL, I dont have enough rep to vote up, and dont know how to accept an answer. Will learn how now. Commented Feb 24, 2011 at 18:51

2 Answers 2

1

Reference link : HERE

Dim SelectQry = "SELECT * FROM [{0}] WHERE [{1}] like '%" & _
                    strYourSearchValue & " %'"
Sign up to request clarification or add additional context in comments.

Comments

0

You can use a LIKE operator to do that.

SELECT * FROM TableName WHERE Name LIKE '%Fizz%' AND Name LIKE '%Bom%'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.