Use native ADO for data inventory.

zhaozj2021-02-08  241

Use native ADO to perform data storage, this example can be displayed, page down, but there is a problem with the top page. The modified storage, deletion, etc. have problems, and all friends have modified it, I only give the role of a throwing brick.

//.cpp program

/ / -------------------------------------------------------------------------------------------- ---------------------------

#include #pragma HDRSTOP

#include "unit1.h" // --------------------------------------- ---------------------------------- # Pragma package (smart_init) #pragma resource "* .dfm" #include

TFORM1 * FORM1; / / -------------------------------------------- -------------------------------__ fastcall tform1 :: tform1 (tComponent * Owner): TFORM (OWNER) {} // -------------------------------------------------- -------------------------

void __fastcall TForm1 :: Button1Click (TObject * Sender) {VConnect = CreateOleObject ( "ADODB.Connection"); // open connection VConnect.OleFunction ( "Open", "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = D : //ado//bcdemos.mdb; Persist security info = false ");} // ----------------------------- ----------------------------------------------

void __fastcall TForm1 :: Button2Click (TObject * Sender) {VRecordSet = CreateOleObject ( "ADODB.RecordSet"); VRecordSet.OlePropertySet ( "ActiveConnection", VConnect); // set the command type and content VRecordSet.OleFunction ( "Open", "Select * from Employee", vconnect); // Execute instruction showrecord ();} // --------------------------- --------------------------------------------- Void TFORM1 :: ShowRecord () {txtEmpNo-> Text = VarToStr (VRecordSet.OlePropertyGet ( "Fields", "EmpNo")); txtLastName-> Text = VarToStr (VRecordSet.OlePropertyGet ( "Fields", "LastName")); txtFirstName-> Text = VarToStr (VRecordSet.OlePropertyGet ( "Fields", "FirstName")); txtPhone-> Text = VarToStr (VRecordSet.OlePropertyGet ( "Fields", "PhoneExt")); txtHireDate-> Text = VarToStr (VRecordSet.OlePropertyGet ( " Fields "," HireDate ")); txtSalary-> Text = VarToStr (VRecordSet.OlePropertyGet (" Fields "," Salary "));} void __fastcall TForm1 :: Button3Click (TObject * Sender) {VRecordSet.OleFunction (" Update " , "Lastname", txtlastname-> text);} // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------- --------------------------- void __fastcall tform1 :: button4click (TOBJECT * Sender) {if (! VRecordSet.olePropertyget ("bof") ) {VRecordset.olefunction ("MoveFirst"); showrecord ();}} // --------------------------------------------- --------------------------------------------

Void __fastcall tform1 :: button6click (TOBJECT * sender) {if (! VRecordSet.olePropertyget ("bof")) {vRecordset.olefunction ("moveprevious"); showrecord ();}} // -------- -------------------------------------------------- -----------------

Void __fastcall tform1 :: button7click (TOBJECT * Sender) {if (! VRecordset.olePropertyget ("eof")) {vrecordset.olefunction ("MoveNext"); showrecord ();}} // ---------- -------------------------------------------------- ----------------- void __fastcall tform1 :: button5click (Tobject * sender) {// if (! VRecordSet.olePropertyget ("EOF") {vRecordSet.OLEFUNCTION ("MoveLast "); Showrecord (); //}} // ------------------------------------- -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//.h program

/ / -------------------------------------------------------------------------------------------- ---------------------------

#ifndef unit1H # Define unit1H // ------------------------------------------------------------------------------------------------------------------------------------ --------------------------------- # include #include #include < STDCTRLS.HPP> #include #include #include #include #include #include #include #include // -------------------------------------- ------------------------------------- Class TFORM1: PUBLIC TFORM {__ Published: // Ide-Managed Components TPanel * Panel1; TButton * Button1; TButton * Button2; TButton * Button3; TButton * Button4; TButton * Button5; TButton * Button6; TButton * Button7; TLabel * Label1; TEdit * txtEmpNo; TLabel * Label2; TEdit * txtLastName; TLabel * Label3; TEDIT * TXTFIRSTNAME; TLABEL * Label4; TEDIT * TXTPHONE; TLABEL * Label5; TEDIT * TXTHIREDATE; TLABEL * Label6; Tedit * TXTSAlary; void __fastcall but ton1Click (TObject * Sender); void __fastcall Button2Click (TObject * Sender); void __fastcall Button3Click (TObject * Sender); void __fastcall Button4Click (TObject * Sender); void __fastcall Button6Click (TObject * Sender); void __fastcall Button7Click (TObject * Sender ); void __fastcall Button5Click (TObject * Sender); void __fastcall FormCreate (TObject * Sender); private: // User declarations Variant VConnect; Variant VRecordSet; void ShowRecord (); public: // User declarations __fastcall TForm1 (TComponent * Owner) };

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

New Post(0)