1. 下載 PGNP 套件
網址為http://www.pgoledb.com/index.php?option=com_filecabinet&view=files&id=1&Itemid=68
您可以依據您的需求下載伺服器版或桌面版套件.
本次示範為PGNP-Postgres-SE-Trial-1.4.0.3178.exe版本
2. 安裝 PGNP, 基本上很容易, 秉持Windows安裝特性, next...n次就搞定了.
a. 開始安裝
b. License Agreement
b. 接下來安裝產品及設定
c. 產品安裝完成
3. OLEDB的第一支程式
a. 開啟 VS2010 或 VS2012 開啟新專案
FILE -> New Project
b. 設定連接資料庫
TOOLS -> Connect to Database
e. 設定Source or file name: 為資料庫主機, 以及設定使用者帳號及密碼和initial catalog, 並且可以透過Detail Links來設定.
f. 將程式改寫如下,紅字的為增加部份.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.OleDb;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string connectString = null;
OleDbConnection conn;
OleDbDataAdapter adp = new OleDbDataAdapter();
DataSet ds = new DataSet();
int i = 0;
connectString = connectString = "Provider=PGNP.1;Data Source=192.168.22.129;Persist Security Info=True;User ID=enterprisedb;Initial Catalog=edb;Extended Properties=\"PORT=5444;SSL=allow;\"";
conn = new OleDbConnection(connectString);
try
{
conn.Open();
adp.SelectCommand = new OleDbCommand("select empno,ename from emp", conn);
adp.Fill(ds);
adp.Dispose();
conn.Close();
for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
{
Console.WriteLine(ds.Tables[0].Rows[i].ItemArray[0].ToString() + "<>" + ds.Tables[0].Rows[i].ItemArray[1].ToString());
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
}
g. 編譯後執行結果如下:
結論: 整體安裝過程很容易吧~ 標準MS的程序, 唯一的缺點就是"要付費", 呵呵~提供您參考.





沒有留言:
張貼留言