一个在TC中连接SQL的例子。

yjdn 2004-09-25 09:22:42
下面是一个在SQL中找到的一个(我理解是TC连接SQL的例子),但我执行不成功,我编译的时候,下面那两个头文件打不开,但在同一目录下的别的头文件math.h等都可以引用。
#include <sqlfront.h>
#include <sqldb.h>
这两个头文件可以在SQL的安装盘中找到。

下面是联机文档找到的例子。看看有没有谁可以用它来连接SQL,或者提供一个TC连SQL的成功例子。
Call-level Method
Microsoft® SQL Server™ 2000 programs, written using the DB-Library or ODBC API methods, communicate directly with SQL Server through C function calls. DB-Library or ODBC functions pass SQL statements to SQL Server and return the results of queries. The call-level method of programming requires no precompiler; however, you cannot include Transact-SQL statements in your C programs, as you can with Embedded SQL for C (ESQL/C).

For example, to use DB-Library to connect to SQL Server and execute a simple query against the pubs sample database requires source code similar to the following:

#define DBNTWIN32
#include <sqlfront.h>
#include <sqldb.h>

main()
{
DBPROCESS *dbproc;
LOGINREC *login;
RETCODE r;

dbinit();
login = dblogin();
if (login == NULL)
return (1);
DBSETLUSER(login, "my_login");
DBSETLPWD(login, "my_password");
dbproc = dbopen(login, "my_server");
dbfreelogin(login);
if (dbproc == NULL)
return (1);
dbuse(dbproc, "pubs");
dbcmd(dbproc,
"select au_fname from authors where au_lname = 'White'");
r = dbsqlexec(dbproc);
if (r == FAIL)
return (1);
while (1)
{
r = dbresults(dbproc);
if (r == SUCCEED)
{
/* Process the rows with dbnextrow() */
}
if ((r == FAIL) || (r == NO_MORE_RESULTS))
break;
}
return (0);
}

The DB-Library approach, using C function calls, is more verbose and more flexible than the ESQL/C approach, and it can be loosely coupled to any database structure. Because a great deal of the program's behavior can be changed dynamically, DB-Library programs are often general-purpose applications. DB-Library is well-suited for environments where the database structure is not known in advance.
...全文
228 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
yjdn 2004-10-27
  • 打赏
  • 举报
回复
算了,结帖吧
changlin365 2004-10-18
  • 打赏
  • 举报
回复
up
yjdn 2004-10-14
  • 打赏
  • 举报
回复
呵呵,我没把问题说清楚,虽然可以引用头文件,但头文件里的语句不能通过编译,
估计是TC不支持的原因,所以我在这里想找一个TC成功连接SQL的例子。
有兴趣的朋友也可以试一下,上面的语句文档里只说是C连接SQL,至于是什么C,还不知道。
netcoder 2004-10-14
  • 打赏
  • 举报
回复
我没有试过,但应该是可以的
既然已经解决了,通过了编译不就OK了?
yjdn 2004-10-13
  • 打赏
  • 举报
回复
头文件的问题已经解决了,我现在想知道TC到底能不能连接SQL,
如果可以,希望能有一个连接的例子。
netcoder 2004-10-13
  • 打赏
  • 举报
回复
这么说头文件的问题已经不存在了,楼主还有什么问题?
smart_zcg 2004-10-13
  • 打赏
  • 举报
回复
用borland的编译器来生成db-library程序需要BMDBLIB.LIB或者BLDBLIB.LIB 文件,这两个文件是borland的文件,楼主找找看有没有。而且要生成db-library for dos程序需要Borland C++ Compiler version 3.1或更新的版本才可以,所以TC是不是根本就不能生成db-library程序呢?我觉得好像是这样的,不知道楼主找到办法了吗?
大家可以交流一下!
hisi 2004-10-12
  • 打赏
  • 举报
回复
VC使用DB-Library倒是有很多,TC没试过。
hisi 2004-10-12
  • 打赏
  • 举报
回复
你确定你的TC include目录里有这两个文件?
把sqlfront.h sqldb.h添加到TC的include目录里,或者在编译的时候指定这两个文件的包含目录。
在vc的include目录里有。
yjdn 2004-10-12
  • 打赏
  • 举报
回复
也不知道什么原因,已经可以用那个拷贝过来的头文件,
现在需要一个TC连接SQL的例子(请各位帖出代码出来的,先试验一下是否可以执行成功),不知道哪位兄台有,有的话,马上结帖。
qizhanfeng 2004-10-12
  • 打赏
  • 举报
回复
学习
smart_zcg 2004-10-11
  • 打赏
  • 举报
回复
你最好把头文件加全了,你要编写win32程序应该包含下面四个文件的:
#define DBNTWIN32
#include <windows.h>
#include <sqlfront.h>
#include <sqldb.h>

写db-library程序这四个include file一个也不能少,另外在你的程序中还要必须import这个库文件:NTWDBLIB.LIB,才可以。你可以去查查msdn上的相关内容吧!上面说的很清楚。

yjdn 2004-09-26
  • 打赏
  • 举报
回复
The DB-Library approach, using C function calls, is more verbose and more flexible than the ESQL/C approach, and it can be loosely coupled to any database structure. Because a great deal of the program's behavior can be changed dynamically, DB-Library programs are often general-purpose applications. DB-Library is well-suited for environments where the database structure is not known in advance.
-------------------------------------------
DB-Library 方法,使用C函数调用,相对ESQL/c来说是比较详细和灵活的,它可以宽松地连接任何数据库
结构,因为一个强大的程序处理能够有力地改变,DB-Library 程序经常是用于多方面的程序,DB_Library
是非常适合那种结构未知的数据库环境.
yjdn 2004-09-25
  • 打赏
  • 举报
回复
也许应该到C版块去问
yjdn 2004-09-25
  • 打赏
  • 举报
回复
问题是为什么不能引用那两个头文件
passionke 2004-09-25
  • 打赏
  • 举报
回复
是不是还需要安装关于数据库的驱动什么的
yjdn 2004-09-25
  • 打赏
  • 举报
回复
MSSSQL2000程序,被写使用DB-Library or ODBC API 方法,和SQLserver直接地交流通过C 函数调用。
DB-Library or ODBC 函数经过SQL的陈述到SQLServer 及返回查询结果。程序的调用方法不需要预编译
程序,无论如何,你不能在你的C程序里包含T-SQL陈述,但你可以在C中嵌入SQL (ESQL/C)

例如:使用DB-Library 去连接SQLserver 及靠着pubs例子数据库执行一个简单的查询,要求愿代码和下
面的类似。
------------------------------------
我把上面的英文简单的翻译一下。

34,588

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧