使用AD0组件,TADOConnection, TADOTable,TDataSource,TDBGrid,TButton;
这几个组件连接sql2005.我的数据库名字是jianqiu,有个表student。里面数据是学号,姓名,性别,年龄,学院。
怎么设置和测试连接我已经明白了。但是现在我需要显示我的数据库的数据,不管数据怎么样,我只想知道这个流程。就用上面的几个组件。就显示在TDBGrid里面。
谢谢了。数据库sql2005
这几个组件连接sql2005.我的数据库名字是jianqiu,有个表student。里面数据是学号,姓名,性别,年龄,学院。
怎么设置和测试连接我已经明白了。但是现在我需要显示我的数据库的数据,不管数据怎么样,我只想知道这个流程。就用上面的几个组件。就显示在TDBGrid里面。
谢谢了。数据库sql2005
解决方案 »
- 简单问题(送分)
- 请高手帮帮我 运行正常 但关闭时会报错
- 如果知道GIF图片存放的URL,在程序中能否浏览该图片?如何实现?
- 如何编程实现把WebBrowser中内容存储为mht格式
- 我又有问题了,show,showmodal,有什么区别啊??
- C++转成DELPHI语句,很急,请帮帮忙(100分)
- 急! 为什么Delphi7.0中IdPOP3和IdSMTP的属性和事件那么少? 求教用法,有例子最好!!
- 问一下那位高手做过"CA"认证的,帮忙指点一下或给源码参考一下,我从没做过,不知从那下手
- 怎样查看系统信息?
- Focus(老鱼)回答得50分
- 如何将D5中的控件升级到D6中。
- DELPHI MDI窗口加载网页的问题
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
你把ADOTable1 的 Connection 属性设为 ADOConnection1, TableName属性设为数据库已经存在的表名,Active设为true;
然后DataSource1的DataSet属性设为ADOTable1;
在把 DBGrid1的DataSource属性设为DataSource1
这样你数据表里的内容就在 DBGrid1里面显示出来了
Left = 322
Top = 172
Width = 409
Height = 393
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object DBGrid1: TDBGrid
Left = 8
Top = 8
Width = 377
Height = 297
DataSource = DataSource1
TabOrder = 0
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'MS Sans Serif'
TitleFont.Style = []
end
object ADOConnection1: TADOConnection
Connected = True
ConnectionString =
'Provider=SQLOLEDB.1;Password=fjjl;Persist Security Info=True;Use' +
'r ID=sa;Initial Catalog=TmpDB;Data Source=TANGQS'
LoginPrompt = False
Provider = 'SQLOLEDB.1'
Left = 272
Top = 16
end
object ADOTable1: TADOTable
Active = True
Connection = ADOConnection1
CursorType = ctStatic
TableName = 'ht'
Left = 304
Top = 16
end
object DataSource1: TDataSource
DataSet = ADOTable1
Left = 344
Top = 16
end
end
这个设置后的窗体文件
Left = 396
Top = 287
Width = 447
Height = 403
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Panel1: TPanel
Left = 0
Top = 0
Width = 431
Height = 365
Align = alBottom
Color = clMenuBar
TabOrder = 0
object Button1: TButton
Left = 144
Top = 264
Width = 75
Height = 25
Caption = '连接数据库'
TabOrder = 0
OnClick = Button1Click
end
object DBGrid1: TDBGrid
Left = 24
Top = 24
Width = 345
Height = 225
Color = clScrollBar
DataSource = DataSource1
FixedColor = clCream
ReadOnly = True
TabOrder = 1
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'MS Sans Serif'
TitleFont.Style = []
Columns = <
item
Expanded = False
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'MS Sans Serif'
Font.Style = []
Title.Caption = '学生学号'
Title.Font.Charset = DEFAULT_CHARSET
Title.Font.Color = clWindowText
Title.Font.Height = -13
Title.Font.Name = 'MS Sans Serif'
Title.Font.Style = []
Visible = True
end
item
Expanded = False
Title.Caption = '姓名'
Visible = True
end
item
Expanded = False
Title.Caption = '性别'
Visible = True
end
item
Expanded = False
Title.Caption = '年龄'
Visible = True
end
item
Expanded = False
Title.Caption = '学院'
Visible = True
end>
end
end
object DataSource1: TDataSource
DataSet = ADOTable1
Left = 8
Top = 264
end
object ADOTable1: TADOTable
Connection = ADOConnection1
CursorType = ctStatic
TableName = 'student'
Left = 48
Top = 264
end
object ADOConnection1: TADOConnection
Connected = True
ConnectionString =
'Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initi' +
'al Catalog=jianqiu;Data Source=JIANQIU'
Provider = 'SQLOLEDB'
Left = 88
Top = 264
end
end
麻烦了