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();

}

}

}

}

}

相关推荐
Roadinforest15 分钟前
NoSQL的最终一致性:真的可靠吗?
数据库·nosql
敲代码的嘎仔16 分钟前
用 Redis 合并写 + DelayQueue 延迟检测,把视频播放进度写库频率降到 1/60
java·开发语言·数据库·redis·缓存·音视频·高并发
承渊政道1 小时前
PostgreSQL 鸿蒙 PC 适配全记录:从原生交叉编译到 HNP 数据库服务闭环
数据库·postgresql·harmonyos·鸿蒙系统·pc端
风哥2号1 小时前
数据库教程FGMT26‑2-GoldenGate数据库容灾迁移02(OGG同构异构、数据库迁移、数据同步、容灾复制)
数据库·goldengate
牛油果子哥q1 小时前
向量数据库原理与工程选型:FAISS深度剖析、Milvus基础、检索优化、分片与持久化落地
数据库·milvus·faiss
海浪仙人掌1 小时前
流动比率有哪些分析陷阱?流动比率怎么避开这些陷阱?
大数据·数据库·人工智能
庆登登登2 小时前
MySQL Workbench 鸿蒙 PC 适配全记录:从 GTK_X11 桌面程序到 ArkUI 原生数据库工作台
数据库·mysql·harmonyos
2601_963282772 小时前
政企无线对讲系统落地:从设备采购到长期运维的完整工程实践
大数据·运维·数据库
熊文豪2 小时前
OceanBaseVS金仓:一条 SQL 的两条路——KingbaseES 的性能竞争力从哪来
数据库·sql·电科金仓
大模型码小白2 小时前
数据可视化:AI 生成 HTML5 动态交互式数据图表
前端·数据库·人工智能·深度学习·机器学习·信息可视化·html5