在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在BDS\2.0\Bin 下有一个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.
[C语言系列]NET 中C#的switch语句的语法 [系统软件]托拽Explore中的文件到VB.net的窗口 [系统软件]Boost库在XP+Visual C++.net中的安装 [常用软件]新配色面板:Paint.Net3.0RC1官方下载 [常用软件]用内建的“Net Meeting”聊天 [VB.NET程序]Henry的VB.NET之旅(三)—共享成员 [VB.NET程序]Henry的VB.NET之旅(二)—构造与析构 [VB.NET程序]Henry的VB.NET之旅(一)—失踪的窗体 [VB.NET程序]在托盘上显示Balloon Tooltip(VB.NET) [VB.NET程序]Henry手记-VB.NET中动态加载Treeview节点(二)
|