网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的考试资料:

 

标题 完全分析.NET 2005如何连接PgSQL数据库
内容
    本文提供了两种方法帮你分析.NET2005如何连接PgSQL数据库。
    方法一:使用商业组件:PostgreSQLDirect。
    下载后安装在.net的安装目录下。会在.NET2005工具栏出现PostgreSQLDirect组件包含了PgSqlConnection PgSqlCommand PgSqlDataAdapter 等控件,然后在项目里添加引用:CoreLab.Data和CoreLab.PostgreSql,可以拖放控件连接数据库,使用方法2005的和自带控件基本相同。也可以写代码连接数据库,具体代码如下:
    PgSqlDataSet ds = new PgSqlDataSet();
    string sql = "select * from onetest where tid=3000";
    PgSqlConnection con = new PgSqlConnectio
    ("user id=postgres;Password=111111;
    host=LOCALHOST;database=postgres");
    PgSqlDataAdapter da = new PgSqlDataAdapter(sql, con);
    da.Fill(ds);
    this.dataGridView1.DataSource = ds;
    this.dataGridView1.DataMember = ds.Tables[0].ToString();
    方法二:下载:Npgsql1.0-bin-ms2.0.zip。
    解压缩后将其中的两个dll文件复制到工程目录下(和bin同级),然后在项目里添加引:Mono.Security和NPgSQL,在代码里添加using NpgSQL;具体代码如下:
    string sql = "select * from onetest where tid=3000";
    NpgsqlConnection con = new NpgsqlConnection
    ("server=localhost;uid=postgres;pwd=111111;database=postgres");
    NpgsqlDataAdapter da = new NpgsqlDataAdapter(sql,con);
    DataSet ds = new DataSet();
    da.Fill(ds);
    this.dataGridView1.DataSource = ds;
    this.dataGridView1.DataMember = ds.Tables[0].ToString();
随便看

 

在线学习网考试资料包含高考、自考、专升本考试、人事考试、公务员考试、大学生村官考试、特岗教师招聘考试、事业单位招聘考试、企业人才招聘、银行招聘、教师招聘、农村信用社招聘、各类资格证书考试等各类考试资料。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/20 5:23:11