从网上看到的.net对PostgreSQL操作的文章
(http://www.zdnet.com.cn/developer/code/story/0,3800066897,39530081-1,00.htm)
按照他的例子,是要抱错的,主要是一些细节的地方,他没有提到.
需要添加2个dll文件:Mono.Security.dll; Npgsql.dll。
给一个例子大家自己参考一下:
http://pgfoundry.org/frs/?group_id=1000140
(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驱动程序下载地址为: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 }
http://pgfoundry.org/frs/?group_id=1000140