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

How to call the column which is selected in Combobox in SQL?

Gobindap
P: 25
I want to call the column which is selected in combobox. Suppose, a table contains ID, name, A1, A2, A3, A4, A5 ......An. I want to return value from ID, name and a column which is selected from Combobox. (i.e. if A1 is selected in combobox then value from A1 should come if A2 is selected in combobox then value from A2 should come.

Is it possible? If possible then how can I do it? If impossible then how to solve such problems?
Feb 10 '13 #1

✓ answered by wizarddrummer

If you are referring to columns then what is stored in a combo box are the fields for whatever the query or record source of the combo box.
In your question you have ID, Name, A1 ... A5. If your table has 100 records then the combo box will have 100 rows from that table.
If you are able to select ID, Name, A1, A2 or A3, etc. as individual selections, in other words the drop down box displays the ID, Name, A1, etc. on a separate line then you don't have columns you have a field with many different types of data in it.

There would be no way to single out A1 or A2 or A3 if they are a column without creating a drop down box for each column based on a query.

Share this Question
Share on Google+
4 Replies


Rabbit
Expert Mod 10K+
P: 12,422
You can do so by building a dynamic SQL string. That's all I can say without seeing your existing code.
Feb 10 '13 #2

P: 1
If you are referring to columns then what is stored in a combo box are the fields for whatever the query or record source of the combo box.
In your question you have ID, Name, A1 ... A5. If your table has 100 records then the combo box will have 100 rows from that table.
If you are able to select ID, Name, A1, A2 or A3, etc. as individual selections, in other words the drop down box displays the ID, Name, A1, etc. on a separate line then you don't have columns you have a field with many different types of data in it.

There would be no way to single out A1 or A2 or A3 if they are a column without creating a drop down box for each column based on a query.
Feb 11 '13 #3

Gobindap
P: 25
Thank you for your king support.

I think my problem is poorly described. I am making it clear now.

Suppose there are 10 columns in a table as: ID, name, A1, A2, A3, A4, A5, A6, A7 and A8. I want to return records from ID, name and one another column from among A1-A8. The next column I return is selected from dropdown list. Now general SQL to be written will be:
Expand|Select|Wrap|Line Numbers
  1. SELECT ID, name, <column to be selected from list> From ..... Where .....
For this I simply tried
Expand|Select|Wrap|Line Numbers
  1. String col = (String)comboBox.getSelectedItem();
Expand|Select|Wrap|Line Numbers
  1. SELECT ID, name, col FROM ..... WHERE .....
But it did not function correctly.
So, please help me to overcome my problem.
Feb 11 '13 #4

Rabbit
Expert Mod 10K+
P: 12,422
I understand your question. The answer remains the same. You have to build a dynamic SQL string. And again, that's all I can say if you don't post the code you're using. So far, you've only posted one line of code and some generic SQL. The SQL, while code, is unlikely to be the exact line of code that you're actually using.

So unless you post the information that is asked for, there's not much I can do to help.
Feb 11 '13 #5

Post your reply

Sign in to post your reply or Sign up for a free account.