类别:学习文档
日期:2021-07-08 浏览:3169 评论:0
前言 最近由于工作需要,需要选用一种国产数据库,安装到麒麟服务器上。 麒麟服务器推荐数据库:达梦数据库(DM8)。
需引用DmProvider.dll文件;
文件地址:F:\dmdbms\drivers\dotNet\DmProvider\net20\DmProvider.dll 达梦数据库(DM8)安装目录中
using System; using System.Collections.Generic; using System.Linq; using System.Web; using Dm; using System.Data; namespace DMConn { public class MDHelper { /// <summary> /// 获得数据库链接 /// </summary> /// <returns></returns> public DmConnection GetConn() { string strconn = "server=localhost;database=sumjob;User Id=SYSDBA;PWD=SYSDBA"; DmConnection conn = new DmConnection(strconn); conn.Open(); return conn; } //插入数据 public void Insert(string sql) { DmConnection conn = GetConn(); DmCommand cmd = new DmCommand(sql, conn); int effect = cmd.ExecuteNonQuery(); conn.Close();//关闭数据库链接 } /// <summary> /// 删除数据 /// </summary> public void Update(string sql) { DmConnection conn = GetConn(); DmCommand cmd = new DmCommand(sql, conn); int effect = cmd.ExecuteNonQuery(); conn.Close(); } /// <summary> /// 删除数据 /// </summary> public void Delete(string sql) { DmConnection conn = GetConn(); DmCommand cmd = new DmCommand(sql, conn); int effect = cmd.ExecuteNonQuery(); conn.Close(); } /// <summary> ///用DataAdapter 查询数据,返回DataSet /// </summary> public DataSet QueryByDataAdapter(string sql) { DmConnection conn = GetConn(); DmDataAdapter da = new DmDataAdapter(sql, conn); DataSet ds = new DataSet(); da.Fill(ds); return ds; } /// <summary> /// 用ExecuteReader查询数据 /// </summary> public void QueryByExecuteReader() { DmConnection conn = GetConn(); string strCmd = "select * from SYSDBA.Users "; DmCommand cmd = new DmCommand(strCmd, conn); DmDataReader dr = (DmDataReader)cmd.ExecuteReader(); int id; string name; string sex; int age; while (dr.Read()) { id = dr.GetInt32(0); name = dr.GetString(1); sex = dr.GetString(2); age = dr.GetInt32(3); } } } }
本文标题:C# 达梦数据库连接DMHelper基础类
本文链接:https://vtzw.com/post/696.html
版权声明:本文不使用任何协议授权,您可以任何形式自由转载或使用。
发表评论 / 取消回复