Recent

Author Topic: Database name from DBGrid  (Read 802 times)

daveinhull

  • Full Member
  • ***
  • Posts: 234
  • 1 divided by nothing must still be 1!
Database name from DBGrid
« on: December 30, 2018, 04:24:31 pm »
Hi,

Is it possible to get the Database name from the DBGrid. I can get the DataSource and from that the DataSet, but then can't get any further to the Database.

Thanks
Dave
« Last Edit: December 30, 2018, 05:20:49 pm by daveinhull »
Version #:1.8.4 Date 2019-01-08 FPC Version: 3.0.4 and SVN Revision 57972 for x86_64-win64-win32/win64

GetMem

  • Hero Member
  • *****
  • Posts: 3419
Re: Database name from DBGrid
« Reply #1 on: December 30, 2018, 04:39:07 pm »
Assuming that the dataset is a TSQLQuery and DBGrid1 is the name of the grid:
Code: Pascal  [Select]
  1. TSQLQuery(DBGrid1.DataSource.DataSet).DataBase.DatabaseName
Similar typecast is also possible for other type of datasets too.

daveinhull

  • Full Member
  • ***
  • Posts: 234
  • 1 divided by nothing must still be 1!
Re: Database name from DBGrid
« Reply #2 on: December 30, 2018, 04:53:24 pm »
Excellent GetMem, many thanks

Think I've still got a lot to learn!
Version #:1.8.4 Date 2019-01-08 FPC Version: 3.0.4 and SVN Revision 57972 for x86_64-win64-win32/win64

mangakissa

  • Hero Member
  • *****
  • Posts: 888
Re: Database name from DBGrid
« Reply #3 on: December 31, 2018, 08:50:55 am »
Why do you want to know the databasename with your grid?
Lazarus 1.84 (32b) / FPC 3.0.4
Windows 10

daveinhull

  • Full Member
  • ***
  • Posts: 234
  • 1 divided by nothing must still be 1!
Re: Database name from DBGrid
« Reply #4 on: December 31, 2018, 05:31:16 pm »
Hi mangakissa,

Actually I need the ODBCConnection.

What I'm doing is trying to write a procedure that puts filter buttons on each column of a DBGrid (a bit like in MS Excel/Access). I just want to pass the DBGrid as a parameter.

I'm trying to get small buttons in the column title row, but having difficulties, see http://forum.lazarus.freepascal.org/index.php/topic,43711.0.html.

When the button is pressed it opens a Form with a few buttons (like set all, clear all, quite etc.) and a DBGrid with a Bookmarklist in Column 1 and the field where the button was pressed in the second column. I'm also having problems with Bookmarklist see http://forum.lazarus.freepascal.org/index.php/topic,43713.0.html.

However, I've done a work around at the moment which works. The DBGrid in the opened window is fed with a SQLQuery which is pretty simple SELECT ColumnName FROM Table GROUP BY ColumnName.

However, the SQL needs the DB Connection that the main DBGrid is fed from.

I'm also trying to extract the Table name from the original DBGrid dataset, but this could be quite a task unless I keep the oringinal DBGrid query simple, SELECT * FROM Table; then I can get it from the SQL string in the DataSet in the passed DBGrid.

I'm probably making a mountain out of a molehill, but I am learning quite a bit as I'm doing this so enjoying it. I did ask if there was already some control which provided MS Excel/Access filter drop downs but haven't got any replies.

Dave
Version #:1.8.4 Date 2019-01-08 FPC Version: 3.0.4 and SVN Revision 57972 for x86_64-win64-win32/win64

mangakissa

  • Hero Member
  • *****
  • Posts: 888
Re: Database name from DBGrid
« Reply #5 on: December 31, 2018, 06:03:18 pm »
Why not feeding the columns in multiple stringlists (one by each column) and set the uniique option to true. Then you need one query for all the things you need whitout a connection to a database
Lazarus 1.84 (32b) / FPC 3.0.4
Windows 10