Is there a decorator for .net data providers that don’t support SQL parameters?

  .net, ado.net, sql, sqlparameter, windows

I want to allow my users to connect to a database in different ways:

  • either with a DB-specific ADO.NET provider, like e.g. MySqlConnector or Npgsql
  • or by creating a DSN on Windows and then using the types in the System.Data.Odbc namespace to use the database

The latter would be very useful for reasons of backwards compatibility.

In my code, I use the abstract types. In principle, I should be able to use the exact same SQL statements, regardless of which way to connect my customers choose.

Now the problem I face has to do with SQL parameters. Using ODBC, I didn’t find a way to use them, e.g. in a query like

SELECT alpha, beta
FROM gamma
WHERE delta = @epsilon

(edited)

In some SQL dialects ‘:’ instead of ‘@’ is used to prefix parameters, but that is not the issue here. System.Data.Odbc doesn’t seem to pass the parameters whatsoever.

Does there already exist some wrapper around System.Data.Odbc that enables using SQL parameters? Some kind of decorator for System.Data?

Source: Windows Questions

LEAVE A COMMENT