comparing part of a string with predifined values in a DB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CharChabil
    New Member
    • Oct 2006
    • 17

    comparing part of a string with predifined values in a DB

    Hello guys
    I m reading from a text file, and in the same time comparing the read value with predefined values in a DB
    From file:
    EXTERNAL ALARM
    GENERATOR RUNNING KAA
    EDL ARSAL FAILURE

    Having KAA in my database I want to retrieve the ID of this data
    And having ARSAL in my database I want to retrieve the ID of this data

    This is a part of my code,
    I know that this code sounds erroneous,
    Code:
    Dim sr As New IO.StreamReader(src)
    Do While Not sr.Peek = -1
                checkStr = sr.ReadLine
    cmd.CommandText =select ID from table  where name like '%" checkstr & "'"
    end while
    I guess the prob is in “%”,
    Thx for your help
  • bplacker
    New Member
    • Sep 2006
    • 121

    #2
    Originally posted by CharChabil
    Hello guys
    I m reading from a text file, and in the same time comparing the read value with predefined values in a DB
    From file:
    EXTERNAL ALARM
    GENERATOR RUNNING KAA
    EDL ARSAL FAILURE

    Having KAA in my database I want to retrieve the ID of this data
    And having ARSAL in my database I want to retrieve the ID of this data

    This is a part of my code,
    I know that this code sounds erroneous,
    Code:
    Dim sr As New IO.StreamReader(src)
    Do While Not sr.Peek = -1
                checkStr = sr.ReadLine
    cmd.CommandText =select ID from table  where name like '%" checkstr & "'"
    end while
    I guess the prob is in “%”,
    Thx for your help

    the sql statement should be something like:
    select ID from table where name like '%" & checkstr & "%'"

    The % means any number of characters, so putting it before and after checks for the criteria anywhere within the string.

    Comment

    Working...