PDA

View Full Version : کدی برای اتصال SQL به C++



silver_moon_300
یک شنبه 25 دی 1390, 18:43 عصر
با سلام
دیتابیسی به زبان SQL نوشته ام و احتیاج به کدی دارم که آن را به برنامه C++ متصل کند، پیشاپیش از کمک شما متشکرم
(SQL 2008 )

(کامپایلر (Borland C++ 5.02

soorena
یک شنبه 25 دی 1390, 23:13 عصر
http://www.cplusplus.happycodings.com/Algorithms/code1.html

silver_moon_300
دوشنبه 26 دی 1390, 16:24 عصر
سلام

خیلی ممنونم ولی متاسفانه خیلی Error میده، فکر میکنم فایل های سرآیند <sqldb.h> و <sqlfront.h> رو نمی شناسه.


#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);
}

quiet_programmer
چهارشنبه 28 دی 1390, 11:04 صبح
با سلام.


خیلی ممنونم ولی متاسفانه خیلی Error میده، فکر میکنم فایل های سرآیند <sqldb.h> و <sqlfront.h> رو نمی شناسه.

از کامپایلر borland c++ v.5.5.1 (یا همون bcc32.exe)استفاده کن. هر دو سرآیند رو داره.

یاحق.
موفق باشید/

silver_moon_300
پنج شنبه 29 دی 1390, 17:28 عصر
سلام
از راهنمایی شما خیلی ممنونم