当前位置:数据库 > SQLite >>

SQLITE3 在VC/MFC 中使用的一点体会

答案:

SQLITE简介:

This is an extension for the SQLite Embeddable SQL Database Engine. SQLite is a C library that implements an embeddable SQL database engine. Programs that link with the SQLite library can have SQL database access without running a separate RDBMS process.

SQLite is not a client library used to connect to a big database server. SQLite is the server. The SQLite library reads and writes directly to and from the database files on disk.

vc工程目录下 设置 Link  L/对象类模块 sqlite3.lib , c/c++   分类  precompiled  header  选择不使用预补偿页眉

首先将SQLITE3的七个文件放在和vc工程文件同一目录下,在工程中加入 CppSQLite3DB.cppCppSQLite3DB.h文件

# include "CppSQLite3.h"

extern CppSQLite3DB db;/////数据库对象

    remove("c:\\test.db");

    db.open("c:\\test.db");///打开数据库文件

建立表格:

db.execDML("create table Customer(CustomerName char(50), RoomNumber int, CustomerId int, ComeTime int,Money int);");

  db.execDML("create table Room(RoomNumber int, RoomPrice int, RoomState char[20]);");

  db.execDML("create table Manager(ManagerName char[20],PassWord int);");

插入数据:

 string szCmd;

 string szName = m_data1;

szCmd = "insert into Customer values(" ;

 szCmd +="'";

 szCmd +=szName;

szCmd +="'";

szCmd +=",";

sprintf(a,"%d",m_data2);

szCmd += a;

szCmd += ",";

sprintf(b,"%d",m_data3);

szCmd +=b;

szCmd +=","

sprintf(c,"%d",m_data4);

szCmd += c;

szCmd += ",";

sprintf(d,"%d",m_data5);

szCmd += d;

szCmd += ");";

db.execDML(szCmd.c_str());/////////////插入SQL语句

MessageBox("提交成功,请继续!");

更新数据:

   char k[20];//提交后更新房间信息

                   string  szCkd;

                   szCkd="update Room  set  RoomState = 'notnull' where  RoomNumber=";

                      sprintf(k,"%d",m_data2);

                      szCkd +=k;

                      szCkd +=";";

              db.execDML(szCkd.c_str());  //////////插入SQL语句

查询数据:

CppSQLite3Query q = db.execQuery("select * from Customer;");

         while(!q.eof()){

          UpdateData(true);

                if(m_data1==q.getIntField(1))

                {

target="_blank"不符合标准?
下一个:SQLite Mode 数据库交互的小型前端

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,