SQL Server2008怎么预编译C代码,小弟用C代码写的数据库访问程序,求预编译方法 20
//DBMS.cpp:定义控制台应用程序的入口点。//#include"stdafx.h"#include<stdio.h>#include<iostream>#incl...
// DBMS.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<stdio.h>
#include<iostream>
#include<string>
using namespace std;
EXEC SQL BEGIN DECLARE SECTION;
char department[20];
char HSno[9];
char HSname[20];
char HSsex[2];
int HSage;
int NEWAGE;
EXEC SQL END DECLARE SECTION;
long SQLCODE;
EXEC SQL INCLUDE sqlca;//定义SQL通信区
int main()
{
int count=0;
char yn;
printf("Please choose the department name(CS/MA/IS):");
scanf("%s",&department);
EXEC SQL CONNECT TO TEST@localhost:54321 USER "SYSTEM"/"MANAGER";//连接到数据库服务器
EXEC SQL DECLARE SX CURSOR FOR/*定义游标SX*/
SELECT Sno,Sname,Ssex,Sage
FROM Student
WHERE Sdept=:department;
EXEC SQL OPEN SX;
for(;;)
{
EXEC SQL FETCH SX INTO :HSno,:HSname,:HSsex,:HSage;
if(sqlca.sqlcode!=0)
{
break;
}
if(count++==0)
printf("\n% -10s % -20s % -10s % -10s\n","Sno","sname","Ssex","Sage");
printf("% -10s % -20s % -10s % -10d \n",HSno,HSname,HSsex,HSage);
printf("UPDATE AGE(y/n)?");
do
{
scanf("%c",&yn);
}
while(yn!='N'&&yn!='n'&&yn!='Y'&&yn!='y');
if(yn=='y'||yn=='Y')
{
printf("INPUT NEW AGE:");
scanf("%d",&NEWAGE);
EXEC SQL UPDATE Student
SET Sage=:NEWAGE
WHERE CURRENT OF SX;
}
}
EXEC SQL CLOSE SX;
EXEC SQL COMMIT WORK;
EXEC SQL DISCONNECT TEST;
} 展开
//
#include "stdafx.h"
#include<stdio.h>
#include<iostream>
#include<string>
using namespace std;
EXEC SQL BEGIN DECLARE SECTION;
char department[20];
char HSno[9];
char HSname[20];
char HSsex[2];
int HSage;
int NEWAGE;
EXEC SQL END DECLARE SECTION;
long SQLCODE;
EXEC SQL INCLUDE sqlca;//定义SQL通信区
int main()
{
int count=0;
char yn;
printf("Please choose the department name(CS/MA/IS):");
scanf("%s",&department);
EXEC SQL CONNECT TO TEST@localhost:54321 USER "SYSTEM"/"MANAGER";//连接到数据库服务器
EXEC SQL DECLARE SX CURSOR FOR/*定义游标SX*/
SELECT Sno,Sname,Ssex,Sage
FROM Student
WHERE Sdept=:department;
EXEC SQL OPEN SX;
for(;;)
{
EXEC SQL FETCH SX INTO :HSno,:HSname,:HSsex,:HSage;
if(sqlca.sqlcode!=0)
{
break;
}
if(count++==0)
printf("\n% -10s % -20s % -10s % -10s\n","Sno","sname","Ssex","Sage");
printf("% -10s % -20s % -10s % -10d \n",HSno,HSname,HSsex,HSage);
printf("UPDATE AGE(y/n)?");
do
{
scanf("%c",&yn);
}
while(yn!='N'&&yn!='n'&&yn!='Y'&&yn!='y');
if(yn=='y'||yn=='Y')
{
printf("INPUT NEW AGE:");
scanf("%d",&NEWAGE);
EXEC SQL UPDATE Student
SET Sage=:NEWAGE
WHERE CURRENT OF SX;
}
}
EXEC SQL CLOSE SX;
EXEC SQL COMMIT WORK;
EXEC SQL DISCONNECT TEST;
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询