通过 GBase ADO.NET 接口读取 GBase Server 数据需要下面的步骤:
1) 使用 GBaseConnection 创建数据库连接对象 2) 使用 GBaseCommand 创建命令对象 3) 使用连接对象打开连接 4) 设置命令对象的 CommandText 属性,指明查询语句,并关联连接对象
5) 执行命令对象的 ExecuteReader 方法后返回结果集
ExecuteReader方法指定 CommandBehavior.SingleResult参数时返回 单个结果集。
ExecuteReader 方法指定 CommandBehavior.Default 参数时返回多个 结果集。 6) 关闭数据连接
下面的例子将展示如何循环读取某一列的所有数据,并打印出来。 C# 示例: 使用系统; 使用 System.Collections.Generic; 使用System.Linq; 使用系统文本; 使用系统诊断; 使用系统数据; 使用 GBase.Data.GBaseClient; 命名空间 使用AdoNet { 班级课程 { 静态空 主(字符串[] 参数) { 字符串 _ConnStr = “服务器=192.168.5.41;用户 id=root;password=1;database=test;pooling=false“; 使用 (GBaseConnection _Conn = new GBaseConnection(_ConnStr)) { 尝试 { _ 字符串 _CmdText = “选择 * 从 '测试'.'测试'“;
GBase 8a 程序员手册 ADO.NET 篇
南大通用数据技术股份有限公司 - 19 -
GBaseCommand cmd = new GBaseCommand(_CmdText, _Conn); _Conn.Open(); GBase数据读取器 = cmd.ExecuteReader(CommandBehavior.SingleResult); 而(读者。读取()) { Console.WriteLine(reader.获取值(0)); } 读者。关闭(); } catch (GBaseException ex) { Console.WriteLine(例如堆栈跟踪); } 最后 { if( _Conn != 空 ) _Conn.关闭(); } } } } }




