求助:老师叫我做一个管理系统,怎么把vc和sql联系起来啊,各位大哥大姐给个例子吧

qiangqiang1112 2002-07-03 08:55:08
我原来做vc的,可是从来没做过数据库,只是纸面上学过软件工程,那位前辈能指点一二啊,最好能给个简单的例子!谢谢了!
...全文
65 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
qiangqiang1112 2002-07-05
  • 打赏
  • 举报
回复
是啊,我该满足了,谢谢大家!!!!!!!!!!!!!!!!!!!!!!
我还要用bcb做,请大家也关注指教!!!!!!

http://www.csdn.net/expert/topic/850/850979.xml?temp=.9416315
liaomu 2002-07-05
  • 打赏
  • 举报
回复
这些就够了,你还想要什么?
qiangqiang1112 2002-07-05
  • 打赏
  • 举报
回复
还有更多的建议吗?
谢谢诸位大哥大姐了!!!!!!!!
mmzxg 2002-07-04
  • 打赏
  • 举报
回复
可以利用ADO来连接吧!
xingtian713 2002-07-04
  • 打赏
  • 举报
回复
我自己也写过一个封装类,负责与数据打交道,如果你要,我可以给你,xingtian816@sina.com
liaomu 2002-07-04
  • 打赏
  • 举报
回复
说的差不多了。用
rs.GetFieldValue("字段名",变量);
读数据
liyunsong2000 2002-07-04
  • 打赏
  • 举报
回复
我也刚学,希望有人讲得更清楚写
liyunsong2000 2002-07-04
  • 打赏
  • 举报
回复
我也刚学VC,这我也不懂,希望有人教教
liyunsong2000 2002-07-04
  • 打赏
  • 举报
回复
CRecordset rs(&G_db);
rs.Open( CRecordset::forwardOnly, _T( "SELECT * FROM logintab" ) );
lucianliu 2002-07-04
  • 打赏
  • 举报
回复
简单地说可以用CRecordset类
或者在vc中引入ADO对象来完成与数据库的连接
我比较建议用ADO来做
其实vc与数据库的连接可以用多种方法
odbc,oledb,ado,dao etc
liaomu 2002-07-04
  • 打赏
  • 举报
回复
楼上的你别就写一半啊?
要用SELECT语句的话。用crecordset读数据的那部分也写出来啊。
liyunsong2000 2002-07-04
  • 打赏
  • 举报
回复
#include <afxdb.h>
CDatabase G_db;
G_db.OpenEx("DSN=TestDSN;UID=sa;PWD=");
G_db.ExecuteSQL("update testtab set lab1='111' where lab2='3333'");
lurel 2002-07-04
  • 打赏
  • 举报
回复
用ado,odbc都可以连接
liaomu 2002-07-04
  • 打赏
  • 举报
回复
呵呵。很容易的。用crecordset很方便啊。
chenlj188 2002-07-04
  • 打赏
  • 举报
回复
#define DBNTWIN32

#include <stdio.h>

#include <windows.h>

#include <sqlfront.h>

#include <sqldb.h>



// Forward declarations of the error handler and message handler.

int err_handler(PDBPROCESS, INT, INT, INT, LPCSTR, LPCSTR);

int msg_handler(PDBPROCESS, DBINT, INT, INT, LPCSTR, LPCSTR,

LPCSTR, DBUSMALLINT);



main()

{

PDBPROCESS dbproc; // The connection with SQL Server.

PLOGINREC login; // The login information.

DBCHAR name[100];

DBCHAR city[100];



// Install user-supplied error- and message-handling functions.

dberrhandle (err_handler);

dbmsghandle (msg_handler);



// Initialize DB-Library.

dbinit ();



// Get a LOGINREC.

login = dblogin ();

DBSETLUSER (login, "my_login");

DBSETLPWD (login, "my_password");

DBSETLAPP (login, "example");



// Get a DBPROCESS structure for communication with SQL Server.

dbproc = dbopen (login, "my_server");



// Retrieve some columns from the authors table in the

// pubs database.



// First, put the command into the command buffer.

dbcmd (dbproc, "SELECT au_lname, city FROM pubs..authors");

dbcmd (dbproc, " WHERE state = 'CA' ");



// Send the command to SQL Server and start execution.

dbsqlexec (dbproc);



// Process the results.

if (dbresults (dbproc) == SUCCEED)

{

// Bind column to program variables.

dbbind (dbproc, 1, NTBSTRINGBIND, 0, name);

dbbind (dbproc, 2, NTBSTRINGBIND, 0, city);



// Retrieve and print the result rows.

while (dbnextrow (dbproc) != NO_MORE_ROWS)

{

printf ("%s from %s\n", name, city);

}

}



// Close the connection to SQL Server.

dbexit ();



return (0);

}



int err_handler (PDBPROCESS dbproc, INT severity,

INT dberr, INT oserr, LPCSTR dberrstr, LPCSTR oserrstr)

{

printf ("DB-Library Error %i: %s\n", dberr, dberrstr);

if (oserr != DBNOERR)

{

printf ("Operating System Error %i: %s\n", oserr, oserrstr);

}

return (INT_CANCEL);

}



int msg_handler (PDBPROCESS dbproc, DBINT msgno, INT msgstate,

INT severity, LPCSTR msgtext, LPCSTR server,

LPCSTR procedure, DBUSMALLINT line)

{

printf ("SQL Server Message %ld: %s\n", msgno, msgtext);

return (0);

}

qiangqiang1112 2002-07-04
  • 打赏
  • 举报
回复
那用c++builder呢
xjbs 2002-07-03
  • 打赏
  • 举报
回复
问老师去吧,,

34,873

社区成员

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

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