下面的示例使用 DM .NET Data Provider,实现 DM 数据库的连接与查询,代码使用 C#
编写:
首先在项目中引用 DmProvider.dll,DmProvider.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/
评论