我已经加入数据源了,测试也能成功.数据源叫PostgreSQL30.
在Server Explorer中的DATA CONNECTIONS已经加上了ODBC.127.0.0.1 .子目录下的Tables已经有了我的表table1.
我怎么样才能操作这个表呢?我的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.Odbc;
//namespace ConsoleOdbcConnectionnamespace cTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }        private void button1_Click(object sender, EventArgs e)
        {
            string strconn = "Driver={PostgreSQL30};Server=127.0.0.1;Database=test;User=postgres; Password=yes1;Option=3;";            string sql = "select * from \"COUNT_INFO\"";
            OdbcConnection myConnection = new OdbcConnection(strconn);
            OdbcCommand myCommand = new OdbcCommand(sql, myConnection);
            myConnection.Open();
            myConnection.Close();        }
    }
}
//open的时候有错误
ERROR [IM002] [Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序各位好心的人帮帮我吧,谢谢了

解决方案 »

  1.   

    参考:
    Driver={PostgreSQL};Server=IP address;Port=5432;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
    string strconn = "Driver={PostgreSQL30};Server=127.0.0.1;Database=test;User=postgres; Password=yes1;Option=3;"; ->
    string strconn = "Driver={PostgreSQL};Server=127.0.0.1;Database=test;User=postgres; Password=yes1;Option=3;"; 
      

  2.   

    终于解决了~找了好久
                string strconn = "Driver={PostgreSQL ANSI};Server=127.0.0.1;Port=5432;Database=VionCount;Uid=postgres;Pwd=chenqing5151!;";
                OdbcConnection myConnection = new OdbcConnection(strconn);
                myConnection.Open();