/*******************************************************************
*File Name :insert_info_tb.ec
*This is insert basic person informaion into the basic_info_tb
*The database name :
*The table name :basic_info_tb
*Time :2009.5.7
*Author :zhou le xiang
*Compiler command :esql -o insert_info_tb insert_info_tb.ec
*******************************************************************/
//include head
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "sqlca.h"
//define head
exec sql begin declare section;
int id;//use index keyword
char name[20];
int age;
char sex[8];
char tel[12];
char e_mail[30];
char addr[60];
exec sql end declare section;
//main body
int main(int argc,char argv[])
{
int i;
exec sql begin declare section;
int id;
char name[20];
int age;
char sex[8];
char tel[20];
char e_mail[30];
char addr[60];
exec sql end declare section;
printf("Do you want insert data into the basic_info_tb ? 0 ----no or 1 -----yes\n");
printf("choice:");
scanf("%d",&i);
while(i)
{//insert data into the table
fflush(stdout);
exec sql database zlx;
if(sqlca.sqlcode)
{
printf("connect the database error[%d]\n",sqlca.sqlcode);
exit(1);
}
printf("please input your id:");
scanf("%d",&id);
printf("please input your name:");
scanf("%s",&name);
printf("please input your age:");
scanf("%d",&age);
printf("please input your sex:");
scanf("%s",&sex);
printf("please input your tel:");
scanf("%s",&tel);
printf("please input your e_mail:");
scanf("%s",&e_mail);
printf("please input your addr:");
scanf("%s",&addr);
//insert sql
exec sql insert into zlxtb values(:id,:name,:age,:sex,:tel,:e_mail,:addr);
if(sqlca.sqlcode)
{
printf("insert data into table error[%d]\n",sqlca.sqlcode);
exit(1);
}
exec sql close database;
printf("Congratulations ! you insert data into table sccess!\n");
printf("Do you want insert addtion data?0----no or 1----yes\n");
printf("choice:");
scanf("%d",&i);
}
printf("you insert data into table has over ! bye!\n");
return 0;
}
阅读(612) | 评论(0) | 转发(0) |