Page 1 of 1

Using string parameters for items other than values

Posted: Thu 12 Nov 2009 16:39
by cooper13
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.

Posted: Mon 16 Nov 2009 11:33
by Shalex
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.