Hi i've got a problem. I keep getting this awesome error "[Build Error] [Project1.exe] Error 1"
I copied this source code from http://www.daniweb.com/forums/thread56924.html
I just can't seem to get it to work. can someone pls help

#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <odbcinst.h>
#include <sql.h>
#include <sqlext.h>
#include <sqltypes.h>

int main()
{
    SQLHENV env;
    SQLHDBC dbc;
    SQLHSTMT stmt;
    SQLRETURN ret; /* ODBC API return status */
    SQLSMALLINT columns; /* number of columns in result-set */
    int row = 0;
    /* Allocate an environment handle */
    SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);
    /* We want ODBC 3 support */
    SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
    /* Allocate a connection handle */
    SQLAllocHandle(SQL_HANDLE_DBC, env, &dbc);
    /* Connect to the DSN mydsn */
    /* You will need to change mydsn to one you have created and tested */

    SQLDriverConnect(dbc, NULL, (SQLTCHAR FAR *)"DSN=shruthiks;", SQL_NTS,
                    NULL, 0, NULL, SQL_DRIVER_COMPLETE);
    /* Allocate a statement handle */
    SQLAllocHandle(SQL_HANDLE_STMT, dbc, &stmt);
    /* Retrieve a list of tables */
    SQLTables(stmt, NULL, 0, NULL, 0, NULL, 0, (SQLTCHAR FAR *)"TABLE", SQL_NTS);
    /* How many columns are there */
    SQLNumResultCols(stmt, &columns);
    /* Loop through the rows in the result-set */
    while (SQL_SUCCEEDED(ret = SQLFetch(stmt)))
    {
        SQLUSMALLINT i;
        printf("Row %d\n", row++);
        /* Loop through the columns */
        for (i = 1; i <= columns; i++)
        {
            SQLINTEGER indicator;
            char buf[512];
            /* retrieve column data as a string */
            ret = SQLGetData(stmt, i, SQL_C_CHAR,buf, sizeof(buf), &indicator);
            if (SQL_SUCCEEDED(ret))
            {
                /* Handle null columns */
                if (indicator == SQL_NULL_DATA)
                    strcpy(buf, "NULL");
                    
                printf(" Column %u : %s\n", i, buf);
            }
        }
    }
    system("PAUSE");
    return 0;
}

Also linked the project with
lib/libodbc32.a
lib/libodbccp32.a

I just compiled/linked with VC++ 2008 Express without a problem.

What was the exact error message? What you quoted was only an indication that one or more errors occurred.

Compiler: Default compiler
Building Makefile: "C:\Documents and Settings\BradenMurphy\Desktop\DB\Makefile.win"
Executing make...
make.exe -f "C:\Documents and Settings\BradenMurphy\Desktop\DB\Makefile.win" all
g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"

g++.exe main.o -o "2.exe" -L"C:/Dev-Cpp/lib" libodbc32.a libodbccp32.a -lodbc32

g++.exe: libodbc32.a: No such file or directory
g++.exe: libodbccp32.a: No such file or directory

make.exe: *** [2.exe] Error 1

Execution terminated

oh ffs im an idiot:) u gotta include the whole pathname in the linker
C:\Dev-Cpp\lib\libodbc32.a
C:\Dev-Cpp\lib\libodbccp32.a

thx anyway soz for bothering:P

I just finished compiling and linking with Dev-C++ with no problems after adding the libraries.

[edit]Posted this before I saw your previous post (solution) [/edit]

i actually just got one last question. how wud i create a query using this method of connecting to a sql db?
ex: SELECT * FROM table1

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.