從網上看到的.net對PostgreSQL操作的文章
(http://www.zdnet.com.cn/developer/code/story/0,3800066897,39530081-1,00.htm)
按照他的例子,是要抱錯的,主要是一些細節的地方,他沒有提到.
需要添加2個dll檔案:Mono.Security.dll; Npgsql.dll。
給一個例子大家自己參考一下: 1 private void button1_Click(object sender, System.EventArgs e)
2 {
3 richTextBox1.Text = string.Format(
4 "Server={0};Port={1};Userid={2};database=testdb;password={3};Protocol=3;SSL=false;Pooling=true;MinPoolSize=1;MaxPoolSize=20;Encoding=UNICODE;Timeout=60;SslMode=Disable",
5 textBox1.Text.Trim(), textBox2.Text.Trim(), textBox3.Text.Trim(), textBox4.Text.Trim());
6
7 NpgsqlConnection conn = new NpgsqlConnection();
8 conn.ConnectionString = richTextBox1.Text;
9
10 NpgsqlCommand comm = new NpgsqlCommand();
11 comm.Connection = conn;
12 conn.Open();
13 comm.CommandText = @"select * from datas;";
14 DataSet ds = new DataSet();
15 NpgsqlDataAdapter sda = new NpgsqlDataAdapter();
16 sda.SelectCommand = comm;
17 sda.Fill(ds, "datas");
18 if (ds.Tables[0].Rows.Count != 0)
19 {
20 dataGrid1.DataSource = ds.Tables["datas"];
21 MessageBox.Show("OK");
22 }
23 conn.Close();
24 }
PostgreSQL驅動程式為:
http://pgfoundry.org/frs/?group_id=1000140