学生管理部分
#include<myhead.h>
int main(int argc, char *argv[])
{
sqlite3* ppDb=NULL;
if(sqlite3_open("./mydb.db",&ppDb)!=SQLITE_OK)
{
printf("sqlite3_open error:%s\n",sqlite3_errmsg(ppDb));
return -1;
}
//创建数据表
char arg[128]="create table if not exists stu(num int primary key,name char,score double)";
char *errmsg=NULL;
if(sqlite3_exec(ppDb,arg,NULL,NULL,&errmsg)!=SQLITE_OK)
{
printf("%s\n",errmsg);
return -1;
}
int num;
char name;
double score;
while(1)
{
printf("***************学生管理系统************\n");
printf("*************1.添加学生信息************\n");
printf("*************2.删除学生信息************\n");
printf("*************3.修改学生信息************\n");
int a;
scanf("%d",&a);
getchar();
switch(a){
case 1:
{
printf("请输入学号:");
scanf("%d",&num);
getchar();
printf("请输入姓名:");
scanf("%s",&name);
getchar();
printf("请输入成绩:");
scanf("%lf",&score);
getchar();
arg[128]=("insert into stu values (%d,%s,%lf);",num,name,score);
if(sqlite3_exec(ppDb,arg,NULL,NULL,&errmsg)!=SQLITE_OK)
{
printf("%s\n",errmsg);
return -1;
}
printf("学生信息录入成功\n");
}
break;
case 2:
{
printf("请输入学号:");
scanf("%d",&num);
getchar();
arg[128]=("delete from stu where num=%d;",num);
if(sqlite3_exec(ppDb,arg,NULL,NULL,&errmsg)!=SQLITE_OK)
{
printf("%s\n",errmsg);
return -1;
}
printf("学生信息删除成功\n");
}
break;
case 3:
{
printf("请输入学号:");
scanf("%d",&num);
getchar();
printf("请输入成绩:");
scanf("%lf",&score);
getchar();
arg[128]=("update stu set score=%lf where num=%d;",score,num);
if(sqlite3_exec(ppDb,arg,NULL,NULL,&errmsg)!=SQLITE_OK)
{
printf("%s\n",errmsg);
return -1;
}
printf("学生信息修改成功\n");
}
break;
}
}
sqlite3_close(ppDb);
return 0;
}