Yerg Yerg - 7 months ago 25
SQL Question

SQL Invalid syntax with OLEDB Oracle (11g) and C#

Here is the query I want to run:

SELECT COUNT(*) FROM Users WHERE name = @name AND pwd = @pwd;


My Connection String:

Provider=OraOLEDB.Oracle;User Id = HR; Password = hr;


Specifications:


  • C# WinForms

  • Oracle 11

  • OleDBCommand as command

  • Using Oracle XE



Steps I've tried:


  • Script runs in sqldeveloper on the live server

  • Connection opens

  • Listener is up and running

  • Parameters 'name' and 'pwd' got through and are sent



Error I'm getting:


ORA-00936: missing expression

Answer

In Oracle, parameters are prefixed with : instead of @. Use that instead:

SELECT COUNT(*) FROM Users WHERE name = :name AND pwd = :pwd;