Erez
Erez

Reputation: 6446

Parametrized query from .net to Oracle

this is my table in oracle:

enter image description here

I'm trying to do this:

  selectCmd = "select * from scott.BONUS where ename like '% :f4  %'";
        var par = cmd.CreateParameter();
        par.DbType = DbType.String;
        par.ParameterName = "f4";
        par.Value = "fsd";
        cmd.Parameters.Add(par);

        cmd.CommandText = selectCmd;
        con.Open();

my problem is the part after the 'like' .. I've tried many things w/o success. In some of the tries the reader came back empty while in others an exception has been thrown.

Upvotes: 1

Views: 112

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1062600

That is looking for something containing the literal sequence of characters space, colon, f, 4. You mean:

like '%' || :f4 || '%'

(edited to reflect correction by Stephen ODonnell, comments)

Or easier; just use

like :f4

And put the % in the value:

par.Value = "%" + "fsd" + "%";

(expanded for convenience, under the assumption that "fsd" needs to be a variable or similar in the real code)

Upvotes: 1

Related Questions