GBASE南大通用数据库通过 GBase ADO.NET 接口读取数据

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

  1. 使用 GBaseConnection 创建数据库连接对象

  2. 使用 GBaseCommand 创建命令对象

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

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

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

 ExecuteReader方法指定 CommandBehavior.SingleResult参数时返回 单个结果集。

 ExecuteReader 方法指定 CommandBehavior.Default 参数时返回多个 结果集。

  1. 关闭数据连接

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

C# 示例:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Diagnostics;

using System.Data;

using GBase.Data.GBaseClient;

namespace UsingAdoNet

{

class Program

{

static void Main(string[] args)

{

String _ConnStr = "server=192.168.5.41;user id=root;password=1;database=test;pooling=false";

using (GBaseConnection _Conn = new

GBaseConnection(_ConnStr))

{

try

{ _

String _CmdText = "select * from `test`.`test`";

GBaseCommand cmd = new GBaseCommand(_CmdText, _Conn);

_Conn.Open();

GBaseDataReader reader =cmd.ExecuteReader(CommandBehavior.SingleResult);

while (reader.Read())

{

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

}

reader.Close();

}

catch (GBaseException ex)

{

Console.WriteLine(ex.StackTrace);

}

finally

{

if( _Conn != null )

_Conn.Close();

}

}

}

}

}

相关推荐
HalvmånEver21 小时前
MySQL的内置函数
linux·数据库·学习·mysql
m0_7364393021 小时前
Workerman5.0协程实战:PHP高并发新标准
jvm·数据库·python
2301_8180084421 小时前
golang如何实现消息过滤路由_golang消息过滤路由实现要点
jvm·数据库·python
鸡蛋灌Bean21 小时前
mybatis分页深入了解
java·数据库·mybatis
2401_8314194421 小时前
Python分类汇总怎么做_Crosstab交叉表与多条件联合频数频率统计
jvm·数据库·python
2301_7873124321 小时前
Go语言怎么用channel做信号通知_Go语言channel信号模式教程【完整】
jvm·数据库·python
2301_8180084421 小时前
如何删除ASM中的数据文件_ALTER DISKGROUP DROP FILE彻底清除
jvm·数据库·python
IT界的老黄牛21 小时前
MySQL 磁盘告警 1.2TB:从衣柜原理到 gh-ost 卧底,一次释放 540GB 的实战复盘
运维·数据库·mysql
deviant-ART21 小时前
MySQL 实战:如何根据 ID 将表 B 的字段更新到表 A
数据库·mysql
2401_898717661 天前
mysql如何进行全量数据库备份_mysqldump工具的使用技巧
jvm·数据库·python