Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2006

    Unanswered: Send Query From Delphi To MS SQL Server

    I'm trying to connect to an MS SQL Server database, and send a query, but i can't find the soltion. The query would be:

    select count (distinct field1) from TABLE1 where xDATE >= '2007-05-07' AND xDATE <= '2007-06-03'

    What would be the fastest way to do it?

    I would love either step by step instructions, or list of components, or poiting to some tutorial.

    I have been searching all morning, but i can't seem to find a solution.


  2. #2
    Join Date
    Aug 2006
    The Netherlands

    Regarding your task I would use Microsofts ADO framework in conjunction with a ODBC driver. For that first you have to place a TADOConnection component on the form or datamodule. In the 'connectionstring' property of the component you'll have to state something like:
    Provider=MSDASQL.1;Persist Security Info=False;Data Source=DBName
    You can also build a connectionstring with a wizard after clicking the elipsis button at the right side of the entryfield for connectionstring in the Object Inspector.
    Next to that you'll have to place a TADOQuery component which refers to the TADOConnection in the 'connection' property. In the 'SQL' property of the TADOQuery you can write your query. In this you can also define two parameters for both dates that can be set dynamicly in your code.
    Next place a TDataSource component that refers to the TADOQuery with it's 'DataSet' property and finally place a TDBGrid component on the form that has the name of the TDataSource component in it's 'DataSource' property.

    Basically that's it, if all's configured well and the TADOQuery's 'Active' property is true everything happens automaticaly. You can also use another way of datastorage and retrieval (like BDE e.g.) but using ADO gives the lightest application because it depends on Windos own API objects. And you can read more about it in the online help under the section 'Developing Database Applications', chapters 'Connecting to databases', 'Unserstanding datasets' and 'Working with ADO components'.


  3. #3
    Join Date
    Jan 2006
    thanks for the info, your explanation worked flawlessly.

    But to be honest, i thought that dbexpress was lighter and faster than ADO. I'm wrong?

    Also if i use dbexpress, i don't need to setup the odbc connection, right?
    Last edited by kwanbis; 06-14-07 at 19:59.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts