达梦(DM)数据库.NET Data Provider基本示例

MoMo 2021年6月14日21:35:10
评论
259

下面的示例使用 DM .NET Data Provider,实现 DM 数据库的连接与查询,代码使用 C#

编写:

首先在项目中引用 DmProvider.dllDmProvider.dll 达梦数据库安装目录下的 bin 文件

夹下可以找到。

using System;

using System.Collections.Generic;

using System.Text;

using Dm;

namespace DMDemo

{

class Demo

{

//返回结果

static int ret = 1;

static DmConnection cnn = new DmConnection();

[STAThread]

static int Main(string[] args)

{

try

{

cnn.ConnectionString = "Server=localhost; User Id=SYSDBA; PWD=SYSDBA";

cnn.Open();

Demo demo = new Demo();

demo.TestFunc();

cnn.Close();

}

catch(Exception ex)

{

Console.WriteLine(ex.Message);

}

Console.ReadLine();

return ret;

}

public void TestFunc()

{

DmCommand command = new DmCommand();

command.Connection = cnn;

try

{

string a, b, c;

command.CommandText   =   "SELECT   NAME,   AUTHOR,   PUBLISHER   FROM

PRODUCTION.PRODUCT;";

DmDataReader reader = command.ExecuteReader();

while(reader.Read())

{

a = reader.GetString(0);

b = reader.GetString(1);

c = reader.GetString(2);

Console.WriteLine("NAME" + a);

Console.WriteLine("AUTHOR" + b);

Console.WriteLine("PUBLISHER" + c);

Console.WriteLine("-------------------");

}

}

catch(Exception ex)

{

Console.WriteLine(ex.Message);

ret = 0;

}

}

}

}
https://xpanx.com/
MoMo
  • 本文由 发表于 2021年6月14日21:35:10
  • 转载请务必保留本文链接:https://xpanx.com/2995.html
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: