主题:请问怎么用C连接SQL SERVER 2000
//刚学数据库,请问怎么用C连接SQL SERVER 2000,教材只有连接ORACLE的例子.
#include<stdio.h>
#include<stdlib.h>
EXEC SQL INCLUDE sqlca;
main()
{
EXEC SQL BEGIN DECLARE SECTION;
char *username = "Manager/Manager";
char *connectString = "DreamHome";
EXEC SQL END DECLARE SECTION;
//连接到数据库
EXEC SQL CONNET :username USING :connectString;
if(sqlca.sqlcode<0) exit(-1);
//显示消息给用户并创建表
printf("Creating viewing table\n");
EXEC SQL CREATE Viewing( propertyNo VARCHAR2(5) NOT NULL,
clientNo VARCHAR2(5) NOT NULL,
viewDate DATE NOT NULL,
comments VARCHAR2(40));
if (sqlca.sqlcode>=0)
printf("Creation successful\n");
else
Printf("Creation unsuccessful\n");
//交付事务并断开连接
EXEC SQL COMMIT WORK RELEASE;
}
#include<stdio.h>
#include<stdlib.h>
EXEC SQL INCLUDE sqlca;
main()
{
EXEC SQL BEGIN DECLARE SECTION;
char *username = "Manager/Manager";
char *connectString = "DreamHome";
EXEC SQL END DECLARE SECTION;
//连接到数据库
EXEC SQL CONNET :username USING :connectString;
if(sqlca.sqlcode<0) exit(-1);
//显示消息给用户并创建表
printf("Creating viewing table\n");
EXEC SQL CREATE Viewing( propertyNo VARCHAR2(5) NOT NULL,
clientNo VARCHAR2(5) NOT NULL,
viewDate DATE NOT NULL,
comments VARCHAR2(40));
if (sqlca.sqlcode>=0)
printf("Creation successful\n");
else
Printf("Creation unsuccessful\n");
//交付事务并断开连接
EXEC SQL COMMIT WORK RELEASE;
}