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

前端之家收集整理的这篇文章主要介绍了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,m_data3);

szCmd +=b;

szCmd +=","

sprintf(c,m_data4);

szCmd += c;

szCmd += ",";

sprintf(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,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))

{

s.m_data1=q.getStringField(0);

s.m_data2=q.getIntField(1);

s.m_data3=q.getIntField(2);

s.m_data4=q.getFloatField(3);

s.m_data5=q.getIntField(4);

s.DoModal();

UpdateData(false);

break;}

q.nextRow();

if(q.eof()==true)

MessageBox("本旅馆无该房间!");

}

删除数据:

char a[20];

sprintf(a,m_data2);

string szCmd;

szCmd="delete from Room where RoomNumber =" ;

szCmd+=a;

szCmd+=";";

int b=0;

b=db.execDML(szCmd.c_str());

if(b==0)

MessageBox("操作错误,没有该房间信息");

else

MessageBox("删除房间信息成功");

以上为sqlITE3在窗体交互下简易实现几种数据库基本功能的简单说明!

vc工程目录下设置Link L/对象类模块sqlite3.lib,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))

{

s.m_data1=q.getStringField(0);

s.m_data2=q.getIntField(1);

s.m_data3=q.getIntField(2);

s.m_data4=q.getFloatField(3);

s.m_data5=q.getIntField(4);

s.DoModal();

UpdateData(false);

break;}

q.nextRow();

if(q.eof()==true)

MessageBox("本旅馆无该房间!");

}

删除数据:

char a[20];

sprintf(a,m_data2);

string szCmd;

szCmd="delete from Room where RoomNumber =" ;

szCmd+=a;

szCmd+=";";

int b=0;

b=db.execDML(szCmd.c_str());

if(b==0)

MessageBox("操作错误,没有该房间信息");

else

MessageBox("删除房间信息成功");

以上为sqlITE3在窗体交互下简易实现几种数据库基本功能的简单说明!

vc工程目录下设置Link L/对象类模块sqlite3.lib,m_data2);

string szCmd;

szCmd="delete from Room where RoomNumber =" ;

szCmd+=a;

szCmd+=";";

int b=0;

b=db.execDML(szCmd.c_str());

if(b==0)

MessageBox("操作错误,没有该房间信息");

else

MessageBox("删除房间信息成功");

以上为sqlITE3在窗体交互下简易实现几种数据库基本功能的简单说明!

原文链接:https://www.f2er.com/sqlite/202994.html

猜你在找的Sqlite相关文章