转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 站长学院 >> Web开发 >> 正文
使用原生ADO进行数据库存取。         ★★★★

使用原生ADO进行数据库存取。

作者:闵涛 文章来源:闵涛的学习笔记 点击数:625 更新时间:2009/4/23 10:48:40

使用原生ADO进行数据存储,本例子能够显示,向下翻页,但向上翻页有问题。修改后的存储,删除等都存在问题,各位朋友修改一下,我只当起个抛砖引玉的作用。

//.cpp程序

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

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
#include <DAO_97.h>

TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

 

void __fastcall TForm1::Button1Click(TObject *Sender)
{
VConnect= CreateOleObject("ADODB.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);
   // 设定指令类型与内容
   VRecordSet.OleFunction("Open","Select * from employee", VConnect); // 执行指令
   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程序

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

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
#include <ADODB.hpp>
#include <Db.hpp>
#include <ComObj.hpp>
#include <DBGrids.hpp>
#include <Grids.hpp>
//---------------------------------------------------------------------------
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 Button1Click(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);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif


没有相关教程
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · Web开发  · 网页制作
    · 平面设计  · 网站运营
    · 网站推广  · 搜索优化
    · 建站心得  · 站长故事
    · 互联动态
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台