|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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() |
|
#2
|
|||
|
|||
|
Quote:
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 |
|
#3
|
||||
|
||||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Delphi Programming > Connection to SQL Server with Delphi 2006 |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|