Delphi8 in vcl.net Using ADO.NET

xiaoxiao2021-03-06  39

In Delphi.NET, Vcll.Net has two quite regrets:

1. You cannot use ADO (DBGO), but according to Li Wei, this module will have this component.

2. You cannot use ADO.NET and BDP, which will be the theme of my article.

In the Delphi communication area of ​​Borland, Danny said, "Vcll.net in delphi.net can call the WinForm component, and WinForm can also call VCL.NET components."

In order to verify the first sentence, I tried it, in the Vcl.NET, you can use the .NET component, such as you can directly use it system.data.sqlclient, and use the SQLConnection class directly. That is, although the .NET component cannot be seen in the component panel of Vcl.NET, all .NET components, the class, Vcl.net can be used! However, the Dataset of ADO.NET is not compatible with the VCL.NET's DataSet component, so the data perception component cannot be directly called. However, I read Li Wei's Inside VCL knows that there is an ADONETCONNECTOR component, using this component, allowing ADO.NET to support the use of data perception components.

First, the DLL of the VCL.NET component has a borland.vcl.design.donet.dll under BDS / 2.0 / bIN, click the Install .Net Component menu, and then this DLL AddD in the form .NET VCL Components page Let's see the AdonEtConnector component. Then add a DBGRID, DB ...., Datasoure ...., as long as Datasource.DataSet: = AdonEtConnector1. Others are the same as the original Delphi. My specific code is as follows,

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

'Data Source = 192.168.76.170;' 'Initial Catalog = Sfiecerp;'

'password = qWERT;'

'PERSIST Security Info = true;'

'User ID = sa;'

'packet size = 4096;'

'Connection lifetime = 0;'

'Connection Reset = false;'

'Pooling = false;'

'Max pool size = 100; min pool size = 0');

CONNECTION.OPEN

PRODATASET: = dataset.create;

Adapter: = SqldataAdapter.create ('Select * from tproduct', connection);

Adapter.Fill (PRODATATIT, 'Product');

AdonEtConnector1.DataTable: = prodataset.tables [0];

END;

End.

转载请注明原文地址:https://www.9cbs.com/read-75753.html

New Post(0)