Using string parameters for items other than values

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for universal data access
Post Reply
cooper13
Posts: 2
Joined: Thu 12 Nov 2009 16:28

Using string parameters for items other than values

Post by cooper13 » Thu 12 Nov 2009 16:39

I'm trying to use parameters to build a command where the table name is inserted dynamically. However, the table name string is inserted into the command with single quotes which generate SQL errors. Here's a simple example:

String^ tname = "mytable";
uniCmdSelectAll->CommandText = "select * from :tablename";
uniCmdSelectAll->Parameters->Clear();
uniCmdSelectAll->Parameters->Add(":tablename",tname);

Devart::Data::Universal::UniDataReader^ tableReader = uniCmdSelectAll->ExecuteReader();


ExecuteReader() throws an exception because it tries to issue the following SQL:
select * from 'mytable'

Is there any way to use parameters to reference table names and/or to force it to not translate with single quotes?

PS I'm using the 3.0.1 beta.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Post by Shalex » Mon 16 Nov 2009 11:33

You use parameters in a wrong way. The SQL text is not modified by parameters in most cases. We recommend you to use a string concatenation for your CommandText property.

Post Reply