If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > Send Query From Delphi To MS SQL Server

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-14-07, 08:59
kwanbis kwanbis is offline
Registered User
 
Join Date: Jan 2006
Posts: 5
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.

Thanks.
Reply With Quote
  #2 (permalink)  
Old 06-14-07, 15:40
Tyveleyn Tyveleyn is offline
Registered User
 
Join Date: Aug 2006
Location: The Netherlands
Posts: 248
Hi,

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:
Quote:
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'.

Regards
Reply With Quote
  #3 (permalink)  
Old 06-14-07, 17:16
kwanbis kwanbis is offline
Registered User
 
Join Date: Jan 2006
Posts: 5
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 18:59.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On