GBASE南大通用读取数据库数据

GBASE南大通用读取数据库数据

技术教程gslnedu2025-03-10 13:23:536A+A-

通过GBASE南大通用 ADO.NET 接口读取GBASE南大通用Server 数据需要下面的步骤:

1) 使用 GBASE南大通用Connection 创建数据库连接对象

2) 使用 GBASE南大通用Command 创建命令对象

3) 使用连接对象打开连接

4) 设置命令对象的 CommandText 属性,指明查询语句,并关联连接对象

5) 执行命令对象的 ExecuteReader 方法后返回结果集

ExecuteReader方法指定
CommandBehavior.SingleResult参数时返回

单个结果集。

ExecuteReader 方法指定 CommandBehavior.Default 参数时返回多个

结果集。

6) 关闭数据连接

下面的例子将展示如何循环读取某一列的所有数据,并打印出来。

C# 示例:

使用系统;

使用
System.Collections.Generic;

使用 System.Linq;

使用 System.Text;

使用 System.Diagnostics;

使用 System.Data;

使用 GBase.Data.GBaseClient;

命名空间: UsingAdoNet

{

课程安排

{

静态 void Main(string[] 参数)

{

字符串 _ConnStr = “服务器=192.168.5.41;用户

id=根;密码=1;数据库=测试;pooling=false“;

using (GBaseConnection _Conn = new

GBaseConnection(_ConnStr))

{

尝试

{

_ 字符串 _CmdText = “select * from

'测试'.'测试'“;

GBaseCommand cmd = 新的 GBaseCommand(_CmdText,

_Conn);

_Conn.打开();

GBaseDataReader 读取器 =

cmd.ExecuteReader(命令行为.SingleResult);

而 (读者。读())

{

Console.WriteLine(reader.GetValue(0));

}

读者。关闭();

}

catch (GBaseException ex)

{

Console.WriteLine(例如。StackTrace);

}

最后

{

if( _Conn != null )

_Conn.关闭();

}

}

}

}

}

-gbase南大通用

点击这里复制本文地址 以上内容由朽木教程网整理呈现,请务必在转载分享时注明本文地址!如对内容有疑问,请联系我们,谢谢!
qrcode

朽木教程网 © All Rights Reserved.  蜀ICP备2024111239号-8