简体   繁体   中英

How to show same column in dbgrid with different criteria

i need your help to finish my delphi homework.

I use ms access database and show all data in 1 dbgrid using sql. I want to show same column but with criteria (50 record per column) i want select query to produce output like:

No   | Name | No    | Name |
1    | A    | 51    | AA   | 
2    | B    | 52    | BB   | 
3~50 |      | 53~100|      |

Is it possible ?

I can foresee issues if you choose to return a dataset with duplicate column names. To fix this, you must change your query to enforce strictly unique column names, using as . For example...

select A.No as No, A.Name as Name, B.No as No2, B.Name as Name2 from TableA A
  join TableB B on B.Something = A.Something

Just as a note, if you're using a TDBGrid , you can customize the column titles. Right-click on the grid control in design-time and select Columns Editor... and a Collection window will appear. When adding a column, link it to a FieldName and then assign a value to Title.Caption . This will also require that you set up all columns. When you don't define any columns here, it automatically returns all columns in the query.

On the other hand, a SQL query may contain duplicate field names in the output, depending on how you structure the query. I know this is possible in SQL Server , but I'm not sure about MS Access . In any case, I recommend always returning a dataset with unique column names and then customizing the DB Grid's column titles. After all, it is also possible to connect to an excel spreadsheet, which can very likely have identical column names. The problem arrives when you try to read from one of those columns for another use.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM