Delphi演示使用ADO讀取SQLServer2000中的數據,僅包括代碼實現部分,不會連接Sql2000數據庫的朋友可參考一下代碼,連接後將嘗試讀取數據表中的內容,並以DATAGrid的形式顯示出來。下面的測試運行圖:
01
unit
Unit1;
02
interface
03
uses
04
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
05
Dialogs, DB, ADODB, Grids, DBGrids, StdCtrls;
06
type
07
TForm1 =
class
(TForm)
08
DBGrid1: TDBGrid;
09
DataSource1: TDataSource;
10
ADOTable1: TADOTable;
11
Button1: TButton;
12
procedure
Button1Click(Sender: TObject);
13
private
14
{ Private declarations }
15
public
16
{ Public declarations }
17
end
;
18
var
19
Form1: TForm1;
20
implementation
21
{$R *.dfm}
22
{Provider=SQLOLEDB.1;
23
Integrated Security=SSPI;
24
Persist Security Info=False;
25
Initial Catalog=NewDataBase;
26
Data Source=xuzheping}
27
TForm1
.
28
begin
29
Try
30
ADOTable1
Active:=
True
//激活SQL Server 20000服務器的表格數據
31
except
32
ShowMessage(
'某個環節出錯了'
);
//出錯提示信息
33
34
35
本例效果圖: 代碼文件:unit Unit1;inte
//聲明: Arc( DC: HDC;
菜單項通過 ShortCut 屬性來設定快捷鍵, Sho
本例效果圖:代碼文件:unit Unit1;i