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.cpp和Cppsqlite3DB.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)
else
以上为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)
else
以上为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)
else