views:

68

answers:

2

I have a database in MS-Access which has field names as "1", "2", "3", ... "10".

I want to select column 1 then when I click a button, column 2, column 3, ... and so on.

How to do that?

Actually i want to make a project in JSP.

+1  A: 

Those are impractical field names, but you can use brackets to use them in a query:

select [1] from SomeTable where SomeId = 42

A basic rule for designing databases is that data should be in the field values, not in the field names. You should consider redesigning the table so that you store the values in separate rows instead, and have a field that specifies which item is stored in the row:

select Value from SomeTable where SomeId = 42 and ValueType = 1

This will enable you to use a parameterised query instead of creating the query dynamically.

Also, this way you don't have empty fields if you use less than ten items, and the database design doesn't limit you to only ten items.

Guffa
A: 

Suppose I have a table like this

id name

1   name1
2   name2
3   name3
4   name4
5   name5

Now suppose I want to choose record 1 when button 1 is clicked, second record when button 2 is clicked and so on.

So I will write a query like

select * from MyTbl where id = @btnId .

Note:- @btnId will have the value 1 for Button 1, 2 for Button 2 etc.

Or you can use case statement.

This is just an idea for accomplishing the work but as others mentioned, you should be more specific for an accurate answer.

priyanka.sarkar