VC怎样连接,插入,查询PostGre所建的表?

解决方案 »

  1.   

    将PostgreSQL所建数据库配置好ODBC,VC通过ODBC访问。
    VC+ODBC操作,网上有很多。
      

  2.   

    #include "stdafx.h"
    #include <libpq-fe.h>
    void verifyCCon()
    {
    const char *conninfo;
    int i;
    PGconn *conn;
    PGresult *res;
    conninfo = "host=localhost hostaddr=127.0.0.1 port=5432 dbname=postgres user=postgres password=123456";
    printf("before connect\n");
    /* 和数据库建立链接 */
    conn = PQconnectdb(conninfo);
    /*
    * 检查一下与服务器的连接是否成功建立
    */
    if (PQstatus(conn) != CONNECTION_OK)
    {printf("fail\n");
    PQerrorMessage(conn);
    return;
    }
    else
    {
    printf("success\n");
    }PQexec(conn,"create table test1 (name char(20),age int4);");
    PQexec(conn,"insert into test1 values ('cjm',10);");
    PQexec(conn,"insert into test1 values ('eight',20);");
    PQexec(conn,"insert into test1 values ('linuxaid',30);");
    printf("all the date is:\n");
    res = PQexec(conn, "select * from test1;");
    for (int i = 0; i < PQntuples(res); i++)
    {
    for (int j = 0; j < PQnfields(res); j++)
    {
    printf("%15s", PQgetvalue(res, i, j));
    }printf("\n");
    }
    PQclear(res);
    printf("\n\n");
    PQfinish(conn);}int _tmain(int argc, _TCHAR* argv[])
    {
    verifyCCon();return 0;
    }
      

  3.   

    http://bbs.pgsqldb.com/index.php?rid=5197&S=6bdf289497a5ccb4302e18ccf9cbadce&t=msg&th=11029&pl_view=&start=0
      

  4.   

    http://www.jianblog.com/2007/06/21/389/
      

  5.   

    #include  <libpq-fe.h> 
    -----------------------------------
    这个库从哪里或得的啊????
      

  6.   

    #include   <libpq-fe.h>  
    ----------------------------------- 
    这个库从哪里或得的啊????
    up
      

  7.   

    各位大哥,有源码吗?实在是搞不定了啊!救救命吧!环境:Windows XP, VC6.0, PostGre8.3.1