Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old May 7th, 2008, 02:21 AM
slaterm61 slaterm61 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 3 slaterm61 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 42 m 44 sec
Reputation Power: 0
Connection to SQL Server with Delphi 2006

Hi,
I have some vb.net code like this.

How can i do the same in Delphi 2006 ? is it possible to do it all in code, or do you need to use the wizards/designers that are a part of delphi

I'm new to delphi, andi cant seem to find lots of resources online that explain how to do it all in code.



Dim Conn As New OleDb.OleDbConnection
Dim RS As OleDb.OleDbDataReader
Dim SQLcommand As New OleDb.OleDbCommand
Dim sSQL As String = "select * from message where" _ "datediff(ss,current_timestamp,messageDate) > -60"

If Conn.State = ConnectionState.Closed Then
Conn.ConnectionString = "Provider=SQLOLEDB;Data Source=" & ServerName & ";Initial Catalog=news_db;Integrated Security=SSPI;"
Conn.Open()
End If

SQLcommand.CommandTimeout = 15
SQLcommand = Conn.CreateCommand
SQLcommand.CommandText = sSQL
RS = SQLcommand.ExecuteReader()
If RS.HasRows Then
NotifyIcon1.BalloonTipTitle = "New Story"
NotifyIcon1.BalloonTipText = "New Story Available"
NotifyIcon1.ShowBalloonTip(5000)
Threading.Thread.Sleep(60000)
End If
Conn.Close()

Reply With Quote
  #2  
Old May 29th, 2008, 02:21 AM
aikona aikona is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 2 aikona User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 m
Reputation Power: 0
Quote:
Originally Posted by slaterm61
Hi,
I have some vb.net code like this.

How can i do the same in Delphi 2006 ? is it possible to do it all in code, or do you need to use the wizards/designers that are a part of delphi

I'm new to delphi, andi cant seem to find lots of resources online that explain how to do it all in code.



Dim Conn As New OleDb.OleDbConnection
Dim RS As OleDb.OleDbDataReader
Dim SQLcommand As New OleDb.OleDbCommand
Dim sSQL As String = "select * from message where" _ "datediff(ss,current_timestamp,messageDate) > -60"

If Conn.State = ConnectionState.Closed Then
Conn.ConnectionString = "Provider=SQLOLEDB;Data Source=" & ServerName & ";Initial Catalog=news_db;Integrated Security=SSPI;"
Conn.Open()
End If

SQLcommand.CommandTimeout = 15
SQLcommand = Conn.CreateCommand
SQLcommand.CommandText = sSQL
RS = SQLcommand.ExecuteReader()
If RS.HasRows Then
NotifyIcon1.BalloonTipTitle = "New Story"
NotifyIcon1.BalloonTipText = "New Story Available"
NotifyIcon1.ShowBalloonTip(5000)
Threading.Thread.Sleep(60000)
End If
Conn.Close()


To connect to a sql server you need three things ( components ) which you can find it in the tool pallette under DBGo,data access

you need a TAdosql and a Tdatasource and a tdatagrid

In the Tadoquery you can connect to the mssql DB , it will build the same connection string as your vb.
Use the datasource to connect to your Tsql and then connect your datagrid to the datasource

Being a new user I cannot give you adirect link but ... goto delphi-DOT-about-DOT-com and search for database tutorial

Reply With Quote
  #3  
Old May 29th, 2008, 11:36 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,442 Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 h 5 m 45 sec
Reputation Power: 797
You can do it with either TDatabase or TAdoDatabase, something like this (untested code):
Code:
var
   db: TAdoDatabase;
   SQLCommand: TADOCommand;
   rs: TRecordSet;
begin
   db := TAdoDatabase.New(self);
   db.ConnectionString = 'Provider=SQLOLEDB;Data Source=' + ServerName + ';Initial Catalog=news_db;Integrated Security=SSPI;';
   db.LoginPrompt := false;
   db.Open;

   SQLCommand := TADOCommand.New(self);
   SQLCommand.Connection := db;
   SQLCommand.CommandText := sSQL;
  
   rs := SQLCommand.Execute;
end;
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne

Puzzle of the Month solved by sizeablegrin, etienne141 and L7Sqr, superior C/C++ programmers of the month

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > Connection to SQL Server with Delphi 2006


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway