select data from SQL-database using like - InfoPath Dev
in

InfoPath Dev

select data from SQL-database using like

Last post 03-18-2010 02:13 AM by tomasrudh. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 03-17-2010 05:50 AM

    select data from SQL-database using like

    I have made a data connection and some custom code in Visual Basic for Applications to search for data in a SQL database:

     

    Dim myAdoQueryConnection As AdoQueryConnection = Me.DataConnections("brKlientTabel2")

    Dim myNav1 As XPathNavigator = CreateNavigator().SelectSingleNode("/my:myFields/my:CL_OwnersShareholders", NamespaceManager)

    Dim owners As String = myNav1.InnerXml

    myAdoQueryConnection.Command = "SELECT * FROM brKlientTabel WHERE '%" & owners & "%'"

     

    This gives an error message:

    Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

     

    if I select using this line:

    myAdoQueryConnection.Command = "SELECT * FROM brKlientTabel WHERE '" & owners & "%'"

    it works.

     

    There seems to be a problem searching with a percent sign at the very start of the search string, could this be the case, or am I doing something else wrong?

     

    Best regards,

    Tomas Rudh

    Sweden

  • 03-17-2010 08:02 AM In reply to

    Re: select data from SQL-database using like

     Is the error occurring when you try to query the database, or before you do the actual query?  I can't think of a reason why you would get that error, but your query doesn't look right.  Doesn't there need to be some column in the query that you are comparing to that wildcard expression, as in:

     SELECT * FROM brKlientTabel WHERE CoolColumn LIKE '%hello%'

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 03-18-2010 02:13 AM In reply to

    Re: select data from SQL-database using like

    Thanks for your reply, you are quite right, some text fell away, sorry about that:

     

    SELECT * FROM brKlientTabel WHERE Navn LIKE '%hello%'

    The error message appears when I click the button that runs the code, that is when the query is run. If I omit the first % it works just fine.

     

    /Tomas

Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.