Using Ado.net in Delphi.NET's vcl.net.

Source: Internet
Author: User

In Delphi.NET, Vcl.net has two points that are quite regrettable:

1. You cannot use ADO (DBGO), but according to Levi, this component will be available later.

2. You cannot use the ado.net and BDP, which will be the subject of my article.

In Borland's Delphi communication area, I've seen Danny say, "In Delphi.NET Vcl.net can invoke WinForm components, and WinForm can also invoke vcl.net components."

In order to verify the first sentence, try the next, in the vcl.net can be used. NET components, such as direct uses System.Data.SqlClient, and direct use of SqlConnection classes. That is, although the. NET component is not visible in the Vcl.net palette, all the. NET component classes, Vcl.net are available! However, the Ado.net dataset is not compatible with the Vcl.net DataSet component, so the data-aware component cannot be invoked directly. However, looking at Levi's inside VCL knew that there was a adonetconnector component that used this component to enable Ado.net to support the use of data-aware components.

First, the DLL for the Vcl.net component has a Borland.Vcl.Design.AdoNet.dll under Bds2.0bin, click Install. NET component menu, and then on the form's. NET VCL Add this DLL to the Components page to see the Adonetconnector component. Then add a dbgrid,db....,datasoure ..., just datasource.dataset:=adonetconnector1. The other is the same as the original Delphi, it can be. The same method is also effective for the BDP.

The 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 (' ...) ');
Connection.Open;
Prodataset: = dataset.create;
Adapter: = Sqldataadapter.create (' select * from Product ', Connection);
Adapter.fill (Prodataset, ' Product ');
Adonetconnector1.datatable:=prodataset.tables[0];
End
End.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.