By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,454 Members | 1,417 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,454 IT Pros & Developers. It's quick & easy.

OdbcParameters in SELECT clause

P: n/a
I am trying to safely pass the list of fields to select, as in:
OdbcCommand odbcCommand = new OdbcCommand();
odbcCommand.CommandText = "SELECT ? FROM myTable";
odbcCommand.Parameters.Add(new OdbcParameter("@myField",
"myField");
odbcCommand.Connection = myOdbcConnection;
OdbcDataReader odbcDataReader = odbcCommand.ExecuteReader();

This does not work. The returned odbcDataReader did load all expected
rows, but odbcDataReader[0] is set to "myField" (instead of the actual
value of "myField" for each row).

How do I safely pass the list of fields to select using
SQLparameters?

This is using a mySQL ODBC driver.

Thanks!
Jul 5 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
do***********@gmail.com wrote:
I am trying to safely pass the list of fields to select, as in:
OdbcCommand odbcCommand = new OdbcCommand();
odbcCommand.CommandText = "SELECT ? FROM myTable";
odbcCommand.Parameters.Add(new OdbcParameter("@myField",
"myField");
odbcCommand.Connection = myOdbcConnection;
OdbcDataReader odbcDataReader = odbcCommand.ExecuteReader();

This does not work. The returned odbcDataReader did load all expected
rows, but odbcDataReader[0] is set to "myField" (instead of the actual
value of "myField" for each row).

How do I safely pass the list of fields to select using
SQLparameters?

This is using a mySQL ODBC driver.
I am afraid that you don't.

Parameters is for values. Not for table names or field names.

Dynamic SQL with (!!) input data validation or maybe more practical
just SELECT * and pick from the output via field name.

Arne
Jul 5 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.