在delphi.net的VCL.net里使用Ado.net
来源:互联网 发布:三级域名是什么 编辑:程序博客网 时间:2024/05/29 08:17
在delphi.net中,VCL.net有两点蛮遗憾的:
1.不能使用Ado(dbGo),不过据李维说以后将会有这个组件。
2.不能使用Ado.net和BDP,这将是我这片文章的主题。
在Borland的delphi交流区内,曾经看到Danny说过,"在delphi.net中VCL.net可以调用Winform组件,同样Winform也可以调用VCL.net组件"。
为了验证第一句话,我试了下,在VCL.net中是可以使用 .net的组件的,如可以直接uses System.Data.SqlClient,并直接使用 SqlConnection类。也就是说,虽然VCL.net的组件面板中无法看到.net组件,但是所有的.net组件的类,VCL.net都可以使用! 但是,Ado.net的dataset并不和VCL.net的Dataset组件兼容,所以无法直接调用数据感知组件。不过,看了李维的Inside VCL知道原来有一个AdonetConnector组件,用了这个组件,可以使Ado.net支持使用数据感知组件了。
首先,VCL.net组件的dll在BDS2.0Bin 下有一个Borland.VCL.Design.Adonet.dll,单击Install .net component菜单,然后在窗体的.net VCL components页中把这个dll Add一下,就可以看见AdonetConnector组件。然后加一个Dbgrid,db....,datasoure....,只要datasource.dataset:=AdonetConnector1。其它的和原来的delphi一样,就可以了。同样改方法对BDP也有效。
我的具体代码如下,
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,
System.Data.SqlClient,
System.Data, System.ComponentModel, Borland.VCL.StdCtrls,
Borland.VCL.ExtCtrls, Borland.VCL.DBCtrls, Borland.VCL.Grids,
Borland.VCL.DBGrids, Borland.VCL.Db, Borland.VCL.AdonetDb;
type
TForm1 = class(TForm)
Button1: TButton;
AdonetConnector1: TAdonetConnector;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
DBNavigator1: TDBNavigator;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
Connection:SqlConnection;
ProDataSet : DataSet;
Adapter : SqlDataAdapter;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.nfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Connection := SqlConnection.Create('... ');
Connection.Open;
ProDataSet := DataSet.Create;
Adapter := SqlDataAdapter.Create('select * from Product', Connection);
Adapter.Fill(ProDataSet, 'Product');
AdonetConnector1.DataTable:=ProDataSet.Tables[0];
end;
end.
- 在delphi.net的VCL.net里使用Ado.net
- 在delphi.net的VCL.net里使用Ado.net
- delphi8里在VCL.net使用Ado.net
- 通过CrossTalk在Delphi中使用ADO.Net(1)
- 通过CrossTalk在Delphi中使用ADO.Net(1)
- ADO.NET的使用
- 在ado.net中使用ado recordset
- 在asp.net程序里调整ado.net连接池
- 学习笔记》ADO.NET》在ADO.NET中使用DataSet
- ado.net里的datatable与xml
- 使用ADO.NET的场景
- ADO.NET事务的使用
- ADO.NET对象的使用
- 翻譯Borland® Delphi® 2005使用 VCL for .NET移植到 .NET(1)
- 翻譯Borland® Delphi® 2005使用 VCL for .NET移植到 .NET(2)
- 翻譯Borland® Delphi® 2005使用 VCL for .NET移植到 .NET(3)
- ASP.NET里的事务处理(ado.net 数据库应用)
- ASP.NET里的事务处理(ado.net 数据库应用)
- 增强MIDAS的安全性
- 今天做了一个小软件,总结了一些经验与大家共享。
- Dr. Bob的BorCon2003图片报道
- IntraWeb And ActiveForms
- Delphi 8中文帮助-Delphi 8 for .NET是什么?
- 在delphi.net的VCL.net里使用Ado.net
- 使用Delphi创建IIS虚拟目录
- 简单使用Delphi中的TO-DO List
- GSM规范中的部分编码转换
- 搜索字符串在流中的位置
- 用Delphi制作DLL小结
- 使用Delphi和Web Services技术开发短信应用程序
- Delphi例程-应用程序级信息
- 使用IntraWeb进行Web编程