如果可以的话,请给出具体的连接程序,立即给分
---------------------------------------------------------------
当然可以,用嵌入式语句么,但有一定的格式,需要注明是使用了sql语句,
可惜,一下子想不起来了,等我去找找书尽快告诉你
---------------------------------------------------------------
你在SQL 2000的帮助里找ESQL/C就可以找到。
---------------------------------------------------------------
有例程
我贴一点给你
int main(int argc, char argv[])
{
LOGINREC login; // login rec pointer
DBPROCESS* dbproc; // SQL Server connection structure pointer
char cmd[150]; // command buffer
char server[30]; // server name buffer
int x = 1; // command line counter
STATUS retc; // return code
const char* sqlversion; // pointer for version string
*server = '\0'; // null start these two buffers
*cmd = '\0';
if(argc == 1) // if no server name, request it
{
printf("Enter Server Name: ");
gets(server);
}
else // else it was input as first arg
strcpy(server,argv[1]);
if(argc < 2) // if no login id, request it
{
printf("Enter User Name: ");
gets(cmd);
}
else // otherwise it was input as second arg.
strcpy(cmd,argv[2]);
// check to see if communications layer was loaded (DOS ONLY)
if((sqlversion = dbinit()) == (BYTE *)NULL)
{
// DOS TSR (DBNMPIPE.EXE) is not loaded, don't bother going any farther
printf("Error in DB-Library initialization, exiting\n");
return 1;
}
else
printf("DB-Library version: %s\n",sqlversion); // print dblib version
dbsettime(30); // set timeouts to 30 seconds
// set error/msg handlers for this program
dbmsghandle((DBMSGHANDLE_PROC)msg_handler);
dberrhandle((DBERRHANDLE_PROC)err_handler);
login = dblogin(); // get a login rec
DBSETLUSER(login,cmd); // set login id
DBSETLHOST(login,"SQL EXAMPLE"); // set host name for sp_who
DBSETLVERSION(login, DBVER60);
// To use secure, or trusted, connection, uncomment the following line.
// DBSETLSECURE (login);
// open connection to requested server. Pass null server name for local
// connection, if name not entered.
if((dbproc = dbopen(login,(*server) ? server : (char *)NULL)) == (DBPROCESS *)NULL)
{
// no one answered, so couldn't connect or error occurred
printf("Login failed\n");
return 1;
}
else
{
// loop on command input until quit or exit appears in first 4 bytes.
while((strnicmp(cmd,"quit",4) != 0) && (strnicmp(cmd,"exit",4)!=0))
{
printf("%d> ", x++); // print command prompt
gets(cmd); // get command
if(strnicmp(cmd,"go",2) == 0) // is it go
{
if(dbsqlexec(dbproc) == FAIL) // execute command
{
// problem occurred, just try another command
printf("Error in executing command batch!\n");
x = 1;
continue;
}
// command executed correctly, get results information
while((retc = dbresults(dbproc)) != NO_MORE_RESULTS)
{
if (retc == FAIL) // if error get out of loop
break;
// headers and data could be printed here with only two
// function calls, dbprhead(dbproc), and dbprrow(dbproc),
// which would output the headers, and all the data to
// standard output. However, that isn't very informative
// toward understanding how this data is obtained and
// processed, so I do it the hard way, one column at a time.
PrintHeaders(dbproc); // print header data
// loop on each row, until all read
while((retc= dbnextrow(dbproc))!=NO_MORE_ROWS)
{
if(retc == FAIL) // if fail, then clear
{ // connection completely, just
dbcancel(dbproc); // in case.
break;
}
else
PrintRow(dbproc); // else print the current row
}
if (DBCOUNT(dbproc) == 1L) // print the row count
printf("(1 row effected)\n");
else
printf("(%ld rows effected)\n",DBCOUNT(dbproc));
} // end while(dbresults())
x = 1; // reset command line counter
}
else
{
strcat(cmd," "); // go not detected, so put space
dbcmd(dbproc,cmd); // between each command and set in
} // dbproc.
} // end while()
dbclose(dbproc); // quit/exit input, close connection
// print adios and exit.
printf("SQL Server Connection to %s closed, bye bye.\n",server);
return 0;
}
}
/*