Using string parameters for items other than values

Using string parameters for items other than values

Postby 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.
cooper13
 
Posts: 2
Joined: Thu 12 Nov 2009 16:28

Postby 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.
Shalex
Devart Team
 
Posts: 7792
Joined: Thu 14 Aug 2008 12:44


Return to dotConnect Universal